So, for fun I wrote a PlayingCard class with two instance variables, suit and value.
calling collect: [:eachCard | eachCard value] on a collection of cards didn't work as I'd expected, but of course 'value' is the method on Object that returns self. Easily fixed by renaming the 'value' variable to faceValue (and associated accessors), but made me laugh... |
On 12 June 2012 14:27, Jeff Gray <[hidden email]> wrote: So, for fun I wrote a PlayingCard class with two instance variables, suit and PlayingCard>>value will override Object>>value. Noting funny about that. Milan Mimica http://sparklet.sf.net |
On 12 June 2012 14:48, Milan Mimica <[hidden email]> wrote:
> On 12 June 2012 14:27, Jeff Gray <[hidden email]> wrote: >> >> So, for fun I wrote a PlayingCard class with two instance variables, suit >> and >> value. >> calling collect: [:eachCard | eachCard value] >> on a collection of cards didn't work as I'd expected, but of course >> 'value' >> is the method on Object that returns self. >> >> Easily fixed by renaming the 'value' variable to faceValue (and associated >> accessors), but made me laugh... > > > PlayingCard>>value will override Object>>value. Noting funny about that. > i use value for own purposes.. of course, if it fits and if there's no other more appropriate name for an object's property > > -- > Milan Mimica > http://sparklet.sf.net -- Best regards, Igor Stasenko. |
On 12 June 2012 14:55, Igor Stasenko <[hidden email]> wrote:
Me too. Still, nothing funny. But ok, people laugh at different things. Milan Mimica http://sparklet.sf.net |
On Tue, Jun 12, 2012 at 5:52 PM, Milan Mimica <[hidden email]> wrote:
Don't be hard :). He probably was expecting the code to fail, found it wasn't, and he understood why. Learning is fun :) |
In reply to this post by Jeff Gray
On Tue, Jun 12, 2012 at 2:27 PM, Jeff Gray <[hidden email]> wrote: So, for fun I wrote a PlayingCard class with two instance variables, suit and off topic but also fun is that you can do: collect: [:eachCard | eachCard faceValue ] then you can do: collect: #faceValue. but I don't like that..it feels hackish to me. funny, what if you do collect: #value ? hahahaha on a collection of cards didn't work as I'd expected, but of course 'value' -- Mariano http://marianopeck.wordpress.com |
btw, be careful that Object also understands #name :(
On Tue, Jun 12, 2012 at 8:57 PM, Mariano Martinez Peck <[hidden email]> wrote:
-- Mariano http://marianopeck.wordpress.com |
> btw, be careful that Object also understands #name :( which one day we will kill. |
On Tue, Jun 12, 2012 at 9:51 PM, Stéphane Ducasse <[hidden email]> wrote:
soon |
soon Cooool :) we are aligned and armed :) |
The missing part of my story was that being lazy I had not written the value accessor method, so calling calling it in the collect as giving me a collection of cards rather than a collection of the cards' values.
Yes - beginner learning is fun :-) |
Funny - Mariano's comments made me rethink (don't want to do anything hackish :-)) and moving some logic to perhaps a more appropriate class has given me a more elegant solution.
The problem I'm solving is to look at a collection of 7 cards (Texas Holdem: 2 cards per player and 5 community cards) and make the best 5 card poker hand, that can be compared to others. It's a good exercise. |
Free forum by Nabble | Edit this page |