I think in Ruby 1.9 you can do this:
class A
define_singleton_method :loudly do |message|
puts message.upcase
end
end
A.loudly "my message"
# >> MY MESSAGE
More Related Contents:
- How to call methods dynamically based on their name? [duplicate]
- Get the name of the currently executing method
- Executing code for every method call in a Ruby module
- Ruby: Inherit code that works with class variables
- Calling a Method From a String With the Method’s Name in Ruby
- Ruby – print the variable name and then its value
- What does send() do in Ruby?
- How to understand the difference between class_eval() and instance_eval()?
- Dynamically set local variables in Ruby [duplicate]
- Is there a hook similar to Class#inherited that’s triggered only after a Ruby class definition?
- Can I dynamically call a math operator in Ruby?
- How to write a switch statement in Ruby
- Ruby class instance variable vs. class variable
- Ruby Gem install Json fails on Mavericks and Xcode 5.1 – unknown argument: ‘-multiply_definedsuppress’
- “for” vs “each” in Ruby
- String concatenation vs. interpolation in Ruby
- Ruby’s double colon (::) operator usage differences
- When to use RSpec let()?
- How can I use Ruby to colorize the text output to a terminal? [closed]
- How to create a file in Ruby
- What is the “=~” operator in Ruby?
- Ruby send JSON request
- In Ruby is there a way to overload the initialize constructor?
- Invalid active developer path on MAC OS X after installing Ruby
- How to assign hash[‘a’][‘b’]= ‘c’ if hash[‘a’] doesn’t exist?
- Why does white-space affect ruby function calls?
- How to check if a directory/file/symlink exists with one command in Ruby
- Split string by multiple delimiters
- Transliteration in ruby
- How to match something with regex that is not between two special characters?