Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created February 13, 2014 16:29
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 practicingruby/8978473 to your computer and use it in GitHub Desktop.
Save practicingruby/8978473 to your computer and use it in GitHub Desktop.
module Greeter
def greet(name)
"HELLO, #{Name.normalize(name)}!"
end
module Name
def self.normalize(name)
name.strip.upcase
end
end
end
class Name
def initialize(name)
@name = name
end
end
class Person
include Greeter
def initialize(age)
@age = normalize(age)
@name = Name.new("Gregory")
end
private
def normalize(age)
[age.to_i, 25].min
end
end
person = Person.new(12) #=> undefined method `new' for Greeter::Name:Module (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment