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
case 14 | |
when 10..15 | |
puts "Kinda small!" | |
when 80..99 | |
puts "Kinda large!" | |
end |
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
10..15 === 14 # => true | |
80..99 === 14 # => false |
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
point.x = 10 | |
p point.hash # => 910895 | |
p collection.key?(point) # => false |
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
point = Point.new(5, 6) | |
collection = {} | |
collection[point] = 42 | |
p point.hash # => 421522 | |
p collection.key?(point) # => true |
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
require "set" | |
home = Path.new("home", "denis") | |
also_home = Path.new("home", "denis") | |
elsewhere = Path.new("usr", "bin") | |
paths = Set.new | |
paths << home | |
paths.include?(home) # => true |
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
require "set" | |
points = Set.new | |
points << Point.new(11, 24) | |
points.include?(Point.new(11, 24)) # => true | |
points.include?(Point.new(10, 22)) # => false |
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
points = {} | |
points[Point.new(11, 24)] = true | |
points[Point.new(11, 24)] # => true | |
points[Point.new(10, 22)] # => nil |
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 Point | |
# … | |
def hash | |
[self.class, @x, @y].hash | |
end | |
end |
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 Point | |
# … | |
def hash | |
# Do not do this! | |
self.class.hash ^ (@x.hash * 3) ^ (@y.hash * 5) | |
end | |
end |
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 Point | |
# … | |
def hash | |
# Do not do this! | |
self.class.hash ^ @x.hash ^ @y.hash | |
end | |
end |