Created
September 16, 2022 10:25
-
-
Save thiagofm/206465abec3fa3753964b1e18a38c0c2 to your computer and use it in GitHub Desktop.
play_song.rb
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 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