Sha256: 7a0d7f931b3d1d94bb1f048c329185cdb802f9ea11885d7e4c74f5da2bf3f3a2
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
require 'gobstones/modules/equal_by_class' require 'gobstones/runner/errors/gobstones_type_error' module Gobstones module Lang class Literal include Comparable include Gobstones::EqualByClass def evaluate(context=nil) self end def <=>(other) self == other ? 0 : (self < other ? -1 : 1) end def <(other) raise 'subclass responsibility' end def if_true(block, context) raise Gobstones::Runner::GobstonesTypeError, "#{self} is not a boolean" end def if_false(block, context) raise Gobstones::Runner::GobstonesTypeError, "#{self} is not a boolean" end def is_true? raise Gobstones::Runner::GobstonesTypeError, "#{self} is not a boolean" end def same_type_as(other) self.return_type == other.return_type end def return_type raise 'subclass responsibility' end OPERATORS_MAPPING = { :equal => :==, :not_equal => '!='.to_sym, :less_than => :<, :less_equal => :<=, :greater_than => :>, :greater_equal => :>= } OPERATORS_MAPPING.each do |gbs_op, ruby_op| define_method gbs_op do |other| send(ruby_op, other) ? True.new : False.new end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gobstones-0.0.1.1 | lib/gobstones/lang/literals/literal.rb |