Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Forked from wycats/ruby.rb
Created November 10, 2009 04:06
Show Gist options
  • Save alvin2ye/230617 to your computer and use it in GitHub Desktop.
Save alvin2ye/230617 to your computer and use it in GitHub Desktop.
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