Skip to content

Instantly share code, notes, and snippets.

@Freika
Last active June 25, 2019 09:34
Show Gist options
  • Save Freika/834e59e7b3b5cfed866c06be81c77cab to your computer and use it in GitHub Desktop.
Save Freika/834e59e7b3b5cfed866c06be81c77cab to your computer and use it in GitHub Desktop.
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