Not sure is that ever possible, but it would be nice to optimize code this way. I'm trying to do something like this:
$name2 = 'name2'
def ('name1'+$name2)
...
end
Not sure is that ever possible, but it would be nice to optimize code this way. I'm trying to do something like this:
$name2 = 'name2'
def ('name1'+$name2)
...
end
You can use define_method, here is an example:
>> foo = "bar"
=> "bar"
>> define_method("foo_#{foo}") do
?> puts "Hello from method"
>> end
=> :foo_bar
>> foo_bar
=> Hello from method
__method__ is would be helpful.__callee__ instead of __method__ unless you perfectly understand what are you doing. __method__ returns the name of the original method for aliases, which is confusing in most cases.name = "bubba"; eval "def #{name}; 'hi'; end"; bubba #=> "hi". What's that flashing red light in my rear-view window? Oh, no, it's the eval police!