Skip to content

Instantly share code, notes, and snippets.

@seban
Created September 23, 2021 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seban/03ab9a616be5567bcc23cb4c7da66e02 to your computer and use it in GitHub Desktop.
Save seban/03ab9a616be5567bcc23cb4c7da66e02 to your computer and use it in GitHub Desktop.
class CaseTest
def initialize(number)
@number = number
end
def test
case @number
when it_is_eight?
'eight'
when it_is_five?
'five'
else
'whatever'
end
end
private
def it_is_eight?
->(n) { n == 8 }
end
def it_is_five?
->(n) { n == 5 }
end
end
puts CaseTest.new(5).test
puts CaseTest.new(8).test
puts CaseTest.new(15).test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment