-
-
Save practicingruby/8978473 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
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