Skip to content

Instantly share code, notes, and snippets.

@al3rez
Created January 1, 2020 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save al3rez/3dc26510f5f09f72c6bc631a06e19559 to your computer and use it in GitHub Desktop.
Save al3rez/3dc26510f5f09f72c6bc631a06e19559 to your computer and use it in GitHub Desktop.
class Person
attr_reader :first_name, :last_name
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
end
end
class PersonWithFullName < SimpleDelegator
def full_name
first_name + " " + last_name
end
end
person = Person.new("Alireza", "Bashiri")
PersonWithFullName.new(Person).full_name # => Alireza Bashiri
person.full_name # => undefined method `full_name' for main:Person (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment