Ruby Create method dynamiclly using interactive data
Create method dynamiclly using interactive data.
#!/usr/local/bin/ruby
puts "This program will dynamically create a method"
puts "based on interactive data."
puts "Method name?"
method_name = gets
puts "Line of code: "
code = gets
string = %[def #{method_name}\n #{code}\n end] #build a string
eval(string) # define the method
eval(method_name) # call the method