From: Ross Bamford Date: 2005-12-31T20:06:27+09:00 Subject: Re: Fixnums can have instance variables? Cool. On Fri, 30 Dec 2005 07:46:17 -0000, wrote: > This really surprises me: > > 3.instance_variable_set("@unbelievable", "believe it!") > > puts 3.instance_variable_get("@unbelievable") # -> "believe it!" > > which led me to: > > class Fixnum > attr_accessor :note > end > > 13.note = "a baker's dozen" > 25.note = "5 squared" > > notes = [13, 21, 25].collect { |x| x.note } # ["a baker's dozen", nil, > "5 squared"] > > Am I the only person with their jaw on the ground? > :D That one got me, too. I kind of hinted at it in some nuby code I wrote (http://roscopeco.co.uk/code/noob/bitwise.html). Also check out: irb(main):001:0> class Symbol irb(main):002:1> attr_accessor :too irb(main):003:1> end => nil irb(main):004:0> :foo.too => nil irb(main):005:0> :foo.too = 66 => 66 irb(main):006:0> :foo.too => 66 This struck me as pretty cool, too: irb(main):007:0> SomethingElse = Symbol => Symbol irb(main):008:0> :foo.is_a? SomethingElse => true God, Ruby is *good* -- Ross Bamford - rosco@roscopeco.remove.co.uk