From: Scott Shaffer Date: 2013-04-19T06:41:39+09:00 Subject: Re: confusion with Struct class Love U Ruby wrote in post #1105300: > =============================== > Customer = Struct.new(:name, :address) do |x| > def x.greeting > "Hello #{name}!" > end > end > > p Customer.greeting #=> "Hello Customer!" > =============================== You probably intended to write: Customer = Struct.new(:name, :address) do def greeting "Hello #{name}!" end end This will create a method named "greeting" on ALL of your Customer structs. It's a neat trick, since the method won't be seen as a member of the struct. I like even more that you can include a module: module Greeter def greeting "Hello #{name}!" end end Customer = Struct.new(:name, :address) do include Greeter end -- Posted via http://www.ruby-forum.com/.