Join GitHub today
Creating Struct class with length attribute #1724
I think this is a different behavior between Rubinius and both MRI and JRuby. #length is supposed to return the number of instance variables in the Struct object.
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) puts joe.length Test1 = Struct.new(:length) t1 = Test1.new(42) puts t1.length Test2 = Struct.new(:length, :other) t2 = Test2.new(42, "other") puts t2.length
In my understanding the expected results are 3, 1 and 2.
Is supposed by default, but here I explicitly request it to define accessor for field 'length'. Anyway, this is used in BioRuby, and its maintainers are inclined to think it is bug in Rubinius: bioruby/bioruby#52 (comment)
(Personally, I would prefer warning or even exception to be thrown in case of such name clash, because it can lead to very subtle bugs, especially when code contains heavy metaprogramming.)