From: Robert Klemme Date: 2006-05-21T21:39:53+09:00 Subject: Re: foo= methods don't get called inside instance scope without explicit receiver 2006/5/21, Alder Green : > I can see two ways to deal with this issue: > > 1. Always prefix foo.bar= calls with self within foo. This eliminates > the local-variable possible interpration. However, it is kind of > ugly, and it's easy to introduce elusive bugs by forgetting the > prefix. > > 2. Avoid using the bar= syntax. You can either use a seperate setter > method set_bar, or what the code you posted does (set and return bar > to arg if supplied, just return bar otherwise). A nice variant of 2 makes use of the fact that a method can receive a hash without using curly braces: >> class Foo >> def init(params) >> params.each {|k,v| print k,"=",v,"\n"} >> end >> end => nil >> Foo.new.init(:name => "foo", :size => 123) size=123 name=foo => {:size=>123, :name=>"foo"} Instead of printing you can of course use key value pairs for setting instance variables or invoking setters. Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/