I'm not much of a Rails guru but I did get the impression the :method-as-a-key convention was fairly common. My patch was only thinking of making poor noobs such as myself settle in a bit quicker, there's probably a new Ruby 1.9/Rails 3.x convention nowadays.
If I have time I'll submit a pull request and some tests. Thanks M. On Feb 10, 2011, at 9:34 AM, Sean Cribbs wrote: > Mat, > > That makes sense. The lambda form should work for now (I know it's not > elegant). If this becomes important enough for you longer-term, take your > patch and write it up as a pull-request (with specs please). > > Sean Cribbs <[email protected]> > Developer Advocate > Basho Technologies, Inc. > http://basho.com/ > > On Feb 10, 2011, at 12:28 PM, Mat Ellis wrote: > >> Yes, I got NameError: undefined method `foo' for class `Class' when I tried >> that. >> >> M. >> >> On Feb 10, 2011, at 6:48 AM, Sean Cribbs wrote: >> >>> Mat, >>> >>> Did you try method(:foo) ? Method objects respond to :call. >>> >>> Sean Cribbs <[email protected]> >>> Developer Advocate >>> Basho Technologies, Inc. >>> http://basho.com/ >>> >>> On Feb 10, 2011, at 8:29 AM, Mat Ellis wrote: >>> >>>> For anyone else trying to do this, I couldn't find any docs on how to do >>>> dynamic default values. >>>> >>>> Objective: add an auto-generated UUID field to a Click model using >>>> Twitter's simple_uuid gem. >>>> >>>> Class Click >>>> include Ripple::Document >>>> include SimpleUUID >>>> >>>> property :uuid, String, :default => foo >>>> key on :uuid >>>> >>>> def foo >>>> UUID.new.to_guid >>>> end >>>> end >>>> >>>> This just gave me "foo" every time: >>>> >>>> Changing default to UUID.new.to_guid gave me a nice uuid value but the >>>> same one each time. >>>> >>>> I had to make the default property lambda { UUID.new.to_guid } for it to >>>> work. >>>> >>>> Many other gems/plugins have a convention that if your value in these >>>> cases is a symbol it treats it as a local function. This would mean >>>> changing the default function in the Ripple gem to something like >>>> (untested and untried!): >>>> >>>> def default >>>> default = options[:default] >>>> >>>> return nil if default.nil? >>>> if default.is_a? :symbol >>>> type_cast(self.respond_to?(:default) ? self.default : nil) >>>> else >>>> type_cast(default.respond_to?(:call) ? default.call : default) >>>> end >>>> end >>>> >>>> M. >>>> >>>> >>>> >>>> _______________________________________________ >>>> riak-users mailing list >>>> [email protected] >>>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com >>> >> > _______________________________________________ riak-users mailing list [email protected] http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
