Sha256: 08c92c413615e295a2b0a29df846377aa27ad26acfbdf7539c31a05bbfa0206f

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

require 'moosex'

class Point
	include MooseX

	has x: {
		is: :rw,      # read-write (mandatory)
		isa: Integer, # should be Integer
		default: 0,   # default value is 0 (constant)
	}

	has y: {
		is: :rw,
		isa: Integer,
		default: lambda { 0 }, # you should specify a lambda
	}

	def clear! 
		self.x= 0      # to run with type-check you must
		self.y= 0      # use the setter instad @x=
	end

	def to_s
		"Point[x=#{self.x}, y=#{self.y}]"
	end	
end 

class Point3D < Point	
	has z: {
		is: :rw,      # read-write (mandatory)
		isa: Integer, # should be Integer
		default: 0,   # default value is 0 (constant)
	}

	def clear! 
		self.x= 0      # to run with type-check you must
		self.y= 0      # use the setter instad @x=
		self.z= 0
	end

	def to_s
		"Point[x=#{self.x}, y=#{self.y}, z=#{self.z}]"
	end		
end 

p1 = Point.new(x: 4, y:5)
p2 = Point.new()
p3 = Point3D.new(x: 4, y:5, z:6)
p4 = Point3D.new(x: 4, y:5)
p5 = Point3D.new()

puts ">> objects"
puts p1, p2, p3, p4, p5

p1.clear!
p3.clear!

puts ">> clear"
puts p1, p3

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
moosex-0.0.16 samples/point.rb
moosex-0.0.15 samples/point.rb
moosex-0.0.14 samples/point.rb
moosex-0.0.13 samples/point.rb
moosex-0.0.12 samples/point.rb
moosex-0.0.11 samples/point.rb
moosex-0.0.10 samples/point.rb