-
-
Save alvin2ye/230617 to your computer and use it in GitHub Desktop.
This file contains 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 Person | |
attr_reader :name | |
def initialize(name = nil) | |
@name = name | |
end | |
def loud_name | |
@name.upcase | |
end | |
end | |
module Yeller | |
def yell(text) | |
puts "#{@name} says #{text.upcase}!" | |
end | |
end | |
class Person | |
include Yeller | |
end | |
module Queryer | |
def ask(text) | |
puts "#{@name} asks #{text.upcase}?" | |
end | |
end | |
class Person | |
include Queryer | |
def ask(text) | |
text = text.transliterate | |
super | |
end | |
end | |
module Meta | |
def add_method(name) | |
define_method(name) do | |
puts "Inside #{name.to_s.upcase}!" | |
end | |
end | |
end | |
class Person | |
extend Meta | |
add_method :yourmom | |
end | |
Person.new.yourmom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment