class RubimCode::UserVariable

Attributes

name[RW]
type[RW]

Public Class Methods

new(name, type = "undefined") click to toggle source

attr_accessor :level # ToDo: для указания области видимости

# File lib/rubimc.rb, line 25
def initialize(name, type = "undefined")
        @name, @type = name.to_s, type.to_s
end

Public Instance Methods

!=(val) click to toggle source
# File lib/rubimc.rb, line 91
def !=(val); common_operator(val, __method__); end
%(val) click to toggle source
# File lib/rubimc.rb, line 77
def %(val);   common_operator(val, __method__); end
&(val) click to toggle source

Binary Operators:

# File lib/rubimc.rb, line 98
def &(val); common_operator(val, __method__); end
*(val) click to toggle source
# File lib/rubimc.rb, line 75
def *(val);   common_operator(val, __method__); end
**(val) click to toggle source
# File lib/rubimc.rb, line 78
def **(val);common_operator(val, __method__); end
+(val) click to toggle source

Arithmetic Operators:

# File lib/rubimc.rb, line 73
def +(val);   common_operator(val, __method__); end
+@() click to toggle source
# File lib/rubimc.rb, line 85
def +@; common_operator(nil, __method__, unary: true); end
-(val) click to toggle source
# File lib/rubimc.rb, line 74
def -(val);   common_operator(val, __method__); end
-@() click to toggle source

Unary Operators:

# File lib/rubimc.rb, line 84
def -@; common_operator(nil, __method__, unary: true); end
/(val) click to toggle source
# File lib/rubimc.rb, line 76
def /(val);   common_operator(val, __method__); end
<(val) click to toggle source
# File lib/rubimc.rb, line 92
def  <(val); common_operator(val, __method__); end
<<(val) click to toggle source
# File lib/rubimc.rb, line 101
def <<(val); common_operator(val, __method__); end
<=(val) click to toggle source
# File lib/rubimc.rb, line 94
def <=(val); common_operator(val, __method__); end
==(val) click to toggle source

Comparison Operators:

# File lib/rubimc.rb, line 90
def ==(val); common_operator(val, __method__); end
>(val) click to toggle source
# File lib/rubimc.rb, line 93
def  >(val); common_operator(val, __method__); end
>=(val) click to toggle source
# File lib/rubimc.rb, line 95
def >=(val); common_operator(val, __method__); end
>>(val) click to toggle source
# File lib/rubimc.rb, line 102
def >>(val); common_operator(val, __method__); end
^(val) click to toggle source
# File lib/rubimc.rb, line 100
def ^(val); common_operator(val, __method__); end
c_assign=(val) click to toggle source
# File lib/rubimc.rb, line 47
def c_assign=(val)
        RubimCode::Isolator.permit!(self)
        RubimCode::Isolator.permit!(val)

        RubimCode.perror "Undefined variable or method" if val.nil?
        RubimCode.perror "Wrong match types" unless val.is_a? UserVariable

        RubimCode.pout "#{self.name} = #{val};"
end
common_operator(val, operator_sym, **options) click to toggle source
# File lib/rubimc.rb, line 57
def common_operator(val, operator_sym, **options)
        if not val.class.respond_to? :to_s
                RubimCode.perror "Conversion of variable #{val} is impossible. Method 'to_s' not found"
        else 
                if options[:unary]
                        RubimCode::Isolator.permit!(self)
                        UserVariable.new(operator_sym.to_s[0] + self.name, 'expression')
                else
                        RubimCode::Isolator.permit!(self)
                        RubimCode::Isolator.permit!(val)
                        UserVariable.new(self.name + operator_sym.to_s + val.to_s, 'expression')
                end
        end
end
times() { |n| ... } click to toggle source

Range-operators “..” and “…” ToDo: is it need? or use Enumerator?

# File lib/rubimc.rb, line 123
def times
        n = LoopCounter.new
        RubimCode.pout ("for (int #{n}=0; #{n}<#{self}; #{n}++) {")
        RubimCode.level += 1
        yield(n)
        RubimCode.pout ("}")
        RubimCode.level -= 1
end
to_bool() click to toggle source
# File lib/rubimc.rb, line 37
def to_bool
        return true   if self.name == true   || self.name =~ (/(true|t|yes|y|1)$/i)
        return false  if self.name == false  || self.name.blank? || self.name =~ (/(false|f|no|n|0)$/i)
        RubimCode.perror "Can not convert variable #{self} to boolean"
end
to_i() click to toggle source
# File lib/rubimc.rb, line 33
def to_i
        self.name.to_i
end
to_rubim() click to toggle source
# File lib/rubimc.rb, line 43
def to_rubim
        self
end
to_s() click to toggle source
# File lib/rubimc.rb, line 29
def to_s
        "(" + self.name + ")"
end
|(val) click to toggle source
# File lib/rubimc.rb, line 99
def |(val); common_operator(val, __method__); end