Skip to content

Instantly share code, notes, and snippets.

@Bijendra
Created December 4, 2018 16:14
Show Gist options
  • Save Bijendra/3c15d0030dc20d4a9913b943aefb30ee to your computer and use it in GitHub Desktop.
Save Bijendra/3c15d0030dc20d4a9913b943aefb30ee to your computer and use it in GitHub Desktop.
Ruby Metaprogramming examples
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