Skip to content

Instantly share code, notes, and snippets.

@thiagofm
Created September 16, 2022 10:25
Show Gist options
  • Save thiagofm/206465abec3fa3753964b1e18a38c0c2 to your computer and use it in GitHub Desktop.
Save thiagofm/206465abec3fa3753964b1e18a38c0c2 to your computer and use it in GitHub Desktop.
play_song.rb
class PlaySong
def initialize(song)
@song = song
end
def call
# Here you implement your service object
"🎶 #{song}"
end
private
attr_reader :song
# Defining a singleton method call
# Making it easy to call our class without instantiating it
class << self
def call(song)
new(song).call
end
end
end
# Here's the final interface for our service Object
PlaySong.("Call me Maybe") # => "🎶 Call me Maybe"
# Cool, huh? 😎
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment