From: "David A. Black" Date: 2009-06-28T23:18:36+09:00 Subject: Re: Attr Methods and object setters --1926193751-1293460271-1246198701=:4954 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1293460271-1246198701=:4954" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1293460271-1246198701=:4954 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Sun, 28 Jun 2009, Gregory Brown wrote: > On Sat, Jun 27, 2009 at 11:26 PM, Daniel DeLorme wrote: >> Gregory Brown wrote: >>> >>> Anyway, here's a better way to solve the problem that probably >>> addresses your concerns: >>> >>> def name(*args) >>> � � � return @name if args.empty? >>> � � �@name = args.first >>> end >> >> Another way to do this is to use some kind of singleton object >> >> Nothing = Object.new >> def name(value = Nothing) >> �@name = value unless value == Nothing >> �@name >> end At the risk of someone saying that I've made it too cryptic, it could be one line shorter: Nothing = Object.new def name(value = Nothing) @name = value unless value == Nothing end David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) "Ruby 1.9: What You Need To Know" Envycasts with David A. Black http://www.envycasts.com --1926193751-1293460271-1246198701=:4954-- --1926193751-1293460271-1246198701=:4954--