Created
December 4, 2018 16:14
-
-
Save Bijendra/3c15d0030dc20d4a9913b943aefb30ee to your computer and use it in GitHub Desktop.
Ruby Metaprogramming examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def self.add_methods(name) | |
send(:define_method, name) { | |
puts "you have create a new method and output will be displayed" | |
} | |
end | |
end | |
String.add_methods("log_msg") | |
puts "str1".log_msg.inspect | |
#define_method is a private method on the class. | |
#output | |
#you have create a new method and output will be displayed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment