So let's say I have a class as shown 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 with a more detailed study, you can define class methods (not object methods) and that class methods do not have access to object data.
Is there a way to include these methods as object methods and access the object data? I am using Ruby 1.8.6 and the latest version of datamapper.
Avoid all of yourself and become InstanceMethod:
class List include DataMapper::Resource property :id, Serial property :username, String def my_username return self[:username] end end list=List.create(:username=>'jim') list.my_username
Model ( ) Resource ( ). , ( self.my_username), Model ( , ). , Resource ( ).
Model
Resource
self.my_username
() . , 2.x named_scope. , , . DataMapper , . , DataMapper::Collection, all ( , +, -, & |.
named_scope
DataMapper
DataMapper::Collection
all
+
-
&
|
Source: https://habr.com/ru/post/1750475/More articles:Creating notepad in Java - javaConvert entered text to lowercase - javaWhat is the difference between CreateProcess and CreateProcessA? - visual-c ++SOAP JAX-WS client in ruby - soapChildren's windows in MVVM - c #PHP speed optimization - performanceОбслуживание файла через PHP скрипт и безопасная замена этого файла на лету - fileWrite a SQL query to find these values from column A in table X that are NOT present in column B of table Y - sqlHow to style list items (with one class) individually - cssDB4o Linq query - How to check for null rows - stringAll Articles