Skip to content

Instantly share code, notes, and snippets.

@wakproductions
Created July 26, 2021 00:56
Show Gist options
  • Save wakproductions/2d454730e027df217ae2d53aa963ea6e to your computer and use it in GitHub Desktop.
Save wakproductions/2d454730e027df217ae2d53aa963ea6e to your computer and use it in GitHub Desktop.
def positional_arguments(arg1, arg2, arg3)
puts [arg1, arg2, arg3].join(' ')
end
positional_arguments('Hello', 'Jean Luc', 'Picard')
def positional_with_hash(arg, opts = {})
puts [arg, opts[:firstname], opts[:lastname]].join(' ')
end
positional_with_hash('hello', { firstname: 'Jean Luc', lastname: 'Picard'})
positional_with_hash('hello', firstname: 'Jean Luc', lastname: 'Picard')
hash = { firstname: 'Giordi', lastname: 'La Forge' }
positional_with_hash('Hello!', hash)
def keyword_arguments(arg: 'Welcome aboard', firstname:, lastname: )
puts [arg, firstname, lastname].join(' ')
end
# keyword_arguments({ firstname: 'Deanna', lastname: 'Troi' }) # won't work
# keyword_arguments('Greetings', { firstname: 'Deanna', lastname: 'Troi' }) # won't work
keyword_arguments(firstname: 'Deanna', lastname: 'Troi') # will work 👍🏽
class ServiceBase
def self.call(...)
new.call(...)
end
end
class ServiceObject < ::ServiceBase
def call(id: , name: )
[id, name].join(' ')
end
end
ServiceObject.call(id: 'NCC-71807', name: 'Yamato')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment