Skip to content

Instantly share code, notes, and snippets.

@mtungusov
Last active December 20, 2015 14:49
Show Gist options
  • Select an option

  • Save mtungusov/6149492 to your computer and use it in GitHub Desktop.

Select an option

Save mtungusov/6149492 to your computer and use it in GitHub Desktop.
Struct Examples
# 1
class PeerConnected < Struct.new(:source_id, :ip, :port); end
# 2
Struct.new("Point", :x, :y) #=> Struct::Point
origin = Struct::Point.new(0,0) #=> #
# 3
class Point < Struct.new(:x, :y); end
origin = Point.new(0,0)
# 4
Point = Struct.new(:x, :y)
origin = Point.new(0,0)
# 5
Point = Struct.new(:x, :y) do
def translate(x,y)
self.x += x
self.y += y
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment