Skip to content

Instantly share code, notes, and snippets.

@tushartuteja
Created June 20, 2018 19:31
Show Gist options
  • Save tushartuteja/e993d801c3311628dd084e65826f1258 to your computer and use it in GitHub Desktop.
Save tushartuteja/e993d801c3311628dd084e65826f1258 to your computer and use it in GitHub Desktop.
class Person
puts "at the starting of person class"
def self.my_attr_reader variable_name
evaluate_string = "def #{variable_name} \n" +
"return @#{variable_name} \n" +
"end \n"
eval(evaluate_string)
end
my_attr_reader "name"
def initialize name, age
@name = name
@age = age
end
puts "at the end of person class"
end
person = Person.new("Tushar", 27)
puts(person.name)
###### Look Here ########
Person.my_attr_reader "age"
puts (person.age)
###### Code in discussion Ends ##########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment