mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Set operations
This commit is contained in:
parent
8315386b68
commit
6efba3485e
6
ruby.md
6
ruby.md
@ -55,6 +55,12 @@ a multi-line comment with the # character.
|
|||||||
3 | 5 #=> 7
|
3 | 5 #=> 7
|
||||||
3 ^ 5 #=> 6
|
3 ^ 5 #=> 6
|
||||||
|
|
||||||
|
# Overload bitwise operators to perform
|
||||||
|
# set operations
|
||||||
|
[1,2] & [2,3,4] #=> [2]
|
||||||
|
[1,2] | [2,3,4] #=> [1,2,3,4]
|
||||||
|
[1,2] ^ [2,3,4] #=> [1,3,4]
|
||||||
|
|
||||||
# Arithmetic is just syntactic sugar
|
# Arithmetic is just syntactic sugar
|
||||||
# for calling a method on an object
|
# for calling a method on an object
|
||||||
1.+(3) #=> 4
|
1.+(3) #=> 4
|
||||||
|
Loading…
Reference in New Issue
Block a user