I have several methods with the same type of prefixes.
def get_foo # code end def get_bar # code end I want to learn how to generate these prefixes automatically (similar to how it is done in Rails: Model.find_by_smth ).
Those. I want to create a scope get_ in which you can put the foo method and it will automatically get the get_ prefix and will be available as get_foo .
How can this be implemented?
An example of the desired syntax.
module Bar # Π½Π΅ΠΊΠ°Ρ ΠΎΠ±ΡΡΠΊΠ° `get_` end class Foo include Bar <Π½Π΅ΠΊΠ°Ρ ΠΎΠ±ΡΡΡΠΊΠ° ΠΈΠ· Bar> do def foo puts 'Π£ ΠΌΠ΅Π½Ρ Π΅ΡΡΡ ΠΌΡΡΠ»Ρ, ΠΈ Ρ Π΅Ρ Π΄ΡΠΌΠ°Ρ!' end def bar puts 'Π ΠΌΠΎΠΆΠ½ΠΎ Ρ Π΅Ρ ΡΠΎΠΆΠ΅ Π½Π΅ΠΌΠ½ΠΎΠΆΠ΅ΡΠΊΠΎ ΠΏΠΎΠ΄ΡΠΌΠ°Ρ?' end end end foo = Foo.new foo.get_foo # => "Π£ ΠΌΠ΅Π½Ρ Π΅ΡΡΡ ΠΌΡΡΠ»Ρ, ΠΈ Ρ Π΅Ρ Π΄ΡΠΌΠ°Ρ!" foo.get_bar # => "Π ΠΌΠΎΠΆΠ½ΠΎ Ρ Π΅Ρ ΡΠΎΠΆΠ΅ Π½Π΅ΠΌΠ½ΠΎΠΆΠ΅ΡΠΊΠΎ ΠΏΠΎΠ΄ΡΠΌΠ°Ρ?"
Baronly a wrapper, and the methods inFoothemselves (using a wrapper from a module)? Because in the current venture, I do not see much sense. More precisely, I do not see the point in a separate module, if we do the minimum example :) - D-side