Last active
June 25, 2019 09:34
-
-
Save Freika/834e59e7b3b5cfed866c06be81c77cab 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 User | |
def initialize(first_name, last_name) | |
@first_name = first_name | |
@last_name = last_name | |
end | |
def full_name(format = nil) | |
name = "#{@first_name} #{@last_name}" | |
case format.to_sym | |
when :csv | |
klass_name = Object.const_get("#{format.upcase}Format") | |
klass_name.new(name).csv_full_name | |
when :xml | |
'x' + name | |
else | |
name | |
end | |
end | |
end | |
class CSVFormat | |
def initialize(full_name) | |
@full_name = full_name | |
end | |
def csv_full_name | |
"c#{@full_name}" | |
end | |
end | |
p User.new('User', 'Name').full_name('csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment