From: Matthew Kerwin Date: 2013-04-12T07:57:05+09:00 Subject: Re: confusion with Struct class Alex Newone wrote in post #1105332: > Correct me if i'm wrong, but since when ruby 1.9 uses "name" for class > name? I always though that it's Class.new.class.name or Class.class.name > that gives proper result. As Jesus said: "The object x that is passed into the block is the class that is being created by Struct." E.g.: irb(main):001:0> Foo = Struct.new(:a) {|x| p [x, x.class] } [#, Class] => Foo So my `x` is the actual `Foo` class object, not an instance of it. Thus the following are effectively equivalent: Foo = Struct.new(:a) do |x| def x.bar "#{name}bar" end end class Foo attr_accessor :a def Foo.bar "#{name}bar" end end You can see that `name` is being called on the object on which the method Foo is defined, which is the object Foo, which is an instance of Class. -- Posted via http://www.ruby-forum.com/.