4 ms·
With the hash args the order could vary so I had to keep looking up what the possible argument key values could be. You can set slots on objects in any order t
by richcollins 17y ago
With the hash args the order could vary so I had to keep looking up what the possible argument key values could be.
You can set slots on objects in any order that you want to:
Foo.new.set_x(x).set_z(z) ...
- jamesbritt 17y agoThat is insanely ugly. I will pass, thanks.
- richcollins 17y agoSetters are composable and you can modify their behavior. Hash literals ... not so much. It would seem you only see the surface beauty of things. [redacted -- good point]
- extension 17y agoHow about adding this to the Point class? def to_hash {:x => @x, :y => @y} end def to_ary [@x,@y] end def [] i case i when 0,:x @x when 1,:y @y end end Should work if the receiving method interprets the arguments properly.
- jamesbritt 17y ago"It would seem you only see the surface beauty of things." Is that how you defend an API? Insult the user? Holy shit that's stupid.
- sandal 17y agoCan you recommend an Io book for me? I want to hunt down the author and try to encourage them to make their code more Rubyish. Because you know, that's helpful.
- richcollins 17y agoI did recommend to the Io author that he create a Hash literal syntax because I like the fact that Ruby has one ;-) To be clear, I think that it is great that you created this book. I just responded as I did because I'm often frustrated when I use Ruby APIs that sacrifice good design (imo) for syntactic terseness.