-
-
Save frankyston/567da14b17b6295e21e2e041eb8547a0 to your computer and use it in GitHub Desktop.
Ruby - Métodos de instância VS de classe VS lambda
This file contains hidden or 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 Calc | |
def sum(a, b) | |
a + b | |
end | |
def multiply(a, b) | |
a * b | |
end | |
end | |
calc = Calc.new | |
puts calc.sum(3, 3) # 6 | |
puts calc.multiply(3, 3) # 9 |
This file contains hidden or 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 Calc | |
def self.sum(a, b) | |
a + b | |
end | |
def self.multiply(a, b) | |
a * b | |
end | |
end | |
puts Calc.sum(3, 3) # 6 | |
puts Calc.multiply(3, 3) # 9 |
This file contains hidden or 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
module Calc | |
class Sum | |
def self.call(a, b) | |
a + b | |
end | |
end | |
class Multiply | |
def self.call(a, b) | |
a * b | |
end | |
end | |
end | |
puts Calc::Sum.call(3, 3) # 6 | |
puts Calc::Multiply.call(3, 3) # 9 |
This file contains hidden or 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
module Calc | |
Sum = -> (a, b) { a + b } | |
Multiply = -> (a, b) { a * b } | |
end | |
puts Calc::Sum.call(3, 3) # 6 | |
puts Calc::Multiply.call(3, 3) # 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment