-
-
Save practicingruby/8978573 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Greeter = Object.new | |
class << Greeter | |
def greet(name) | |
"HELLO, #{normalize(name)}!" | |
end | |
private | |
def normalize(name) | |
name.strip.upcase | |
end | |
end | |
class Person | |
def initialize(age) | |
@age = normalize(age) | |
end | |
def greet(name) | |
Greeter.greet(name) | |
end | |
private | |
def normalize(age) | |
[age.to_i, 25].min | |
end | |
end | |
person = Person.new(12) | |
p person.greet("Joe") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment