In this Haskell-like comprehensions implementation in Ruby there's some code I've never seen in Ruby:
class Array
def +@
# implementation
end
def -@
# implementation
end
end
What do def +@
and def -@
mean? Where to find (semi-)official informations about them?
DEF means "Definitely." The term DEF is a contraction of the word "definitely." Other abbreviations of "definitely" include: DEFFO.
The definition of def is a slang term that is excellent or first-rate. An example of def used as an adjective is in the phrase "that music is def," which means the music is excellent. adjective.
It means living the life of who you truly are. It's Being authentic.
They are unary +
and -
methods. They are called when you write -object
or +object
. The syntax +x
, for example, is replaced with x.+@
.
Consider this:
class Foo
def +(other_foo)
puts 'binary +'
end
def +@
puts 'unary +'
end
end
f = Foo.new
g = Foo.new
+ f
# unary +
f + g
# binary +
f + (+ g)
# unary +
# binary +
Another less contrived example:
class Array
def -@
map(&:-@)
end
end
- [1, 2, -3]
# => [-1, -2, 3]
They are mentioned here and there's an article about how to define them here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With