Datamapper, defining your own object methods, how?

Posted by Dublinclontarf on Stack Overflow See other posts from Stack Overflow or by Dublinclontarf
Published on 2010-06-17T10:59:38Z Indexed on 2010/06/18 1:43 UTC
Read the original article Hit count: 374

Filed under:
|
|

So lets say I have a class like below

class List
  include DataMapper::Resource
  property :id, Serial  
  property :username, String

  def self.my_username
    return self[:username]
  end
end

list=List.create(:username=>,'jim')
list.my_username

When I run this it tells me that the method cannot be found, and on more investigation that you can only define class methods(not object methods) and that class methods don't have access to objects data.

Is there any way to have these methods included as object methods and get access to object data? I'm using Ruby 1.8.6 and the latest version of datamapper.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about database