Class: RubimCode::UserVariable
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #!=(val) ⇒ Object
- #!@ ⇒ Object
- #%(val) ⇒ Object
-
#&(val) ⇒ Object
Binary Operators:.
- #*(val) ⇒ Object
- #**(val) ⇒ Object
-
#+(val) ⇒ Object
Arithmetic Operators:.
- #+@ ⇒ Object
- #-(val) ⇒ Object
-
#-@ ⇒ Object
Unary Operators:.
- #/(val) ⇒ Object
- #<(val) ⇒ Object
- #<<(val) ⇒ Object
- #<=(val) ⇒ Object
-
#==(val) ⇒ Object
Comparison Operators:.
- #>(val) ⇒ Object
- #>=(val) ⇒ Object
- #>>(val) ⇒ Object
- #^(val) ⇒ Object
- #c_assign=(val) ⇒ Object
- #common_operator(val, operator_sym, **options) ⇒ Object
-
#initialize(name, type = "undefined") ⇒ UserVariable
constructor
attr_accessor :level # ToDo: для указания области видимости.
-
#times {|n| ... } ⇒ Object
Range-operators “..” and “…” ToDo: is it need? or use Enumerator?.
- #to_bool ⇒ Object
- #to_i ⇒ Object
- #to_rubim ⇒ Object
- #to_s ⇒ Object
- #|(val) ⇒ Object
- #~@ ⇒ Object
Constructor Details
#initialize(name, type = "undefined") ⇒ UserVariable
attr_accessor :level # ToDo: для указания области видимости
25 26 27 |
# File 'lib/rubimc.rb', line 25 def initialize(name, type = "undefined") @name, @type = name.to_s, type.to_s end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/rubimc.rb', line 23 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
23 24 25 |
# File 'lib/rubimc.rb', line 23 def type @type end |
Instance Method Details
#!=(val) ⇒ Object
91 |
# File 'lib/rubimc.rb', line 91 def !=(val); common_operator(val, __method__); end |
#!@ ⇒ Object
86 |
# File 'lib/rubimc.rb', line 86 def !@; common_operator(nil, __method__, unary: true); end |
#%(val) ⇒ Object
77 |
# File 'lib/rubimc.rb', line 77 def %(val); common_operator(val, __method__); end |
#&(val) ⇒ Object
Binary Operators:
98 |
# File 'lib/rubimc.rb', line 98 def &(val); common_operator(val, __method__); end |
#*(val) ⇒ Object
75 |
# File 'lib/rubimc.rb', line 75 def *(val); common_operator(val, __method__); end |
#**(val) ⇒ Object
78 |
# File 'lib/rubimc.rb', line 78 def **(val);common_operator(val, __method__); end |
#+(val) ⇒ Object
Arithmetic Operators:
73 |
# File 'lib/rubimc.rb', line 73 def +(val); common_operator(val, __method__); end |
#+@ ⇒ Object
85 |
# File 'lib/rubimc.rb', line 85 def +@; common_operator(nil, __method__, unary: true); end |
#-(val) ⇒ Object
74 |
# File 'lib/rubimc.rb', line 74 def -(val); common_operator(val, __method__); end |
#-@ ⇒ Object
Unary Operators:
84 |
# File 'lib/rubimc.rb', line 84 def -@; common_operator(nil, __method__, unary: true); end |
#/(val) ⇒ Object
76 |
# File 'lib/rubimc.rb', line 76 def /(val); common_operator(val, __method__); end |
#<(val) ⇒ Object
92 |
# File 'lib/rubimc.rb', line 92 def <(val); common_operator(val, __method__); end |
#<<(val) ⇒ Object
101 |
# File 'lib/rubimc.rb', line 101 def <<(val); common_operator(val, __method__); end |
#<=(val) ⇒ Object
94 |
# File 'lib/rubimc.rb', line 94 def <=(val); common_operator(val, __method__); end |
#==(val) ⇒ Object
Comparison Operators:
90 |
# File 'lib/rubimc.rb', line 90 def ==(val); common_operator(val, __method__); end |
#>(val) ⇒ Object
93 |
# File 'lib/rubimc.rb', line 93 def >(val); common_operator(val, __method__); end |
#>=(val) ⇒ Object
95 |
# File 'lib/rubimc.rb', line 95 def >=(val); common_operator(val, __method__); end |
#>>(val) ⇒ Object
102 |
# File 'lib/rubimc.rb', line 102 def >>(val); common_operator(val, __method__); end |
#^(val) ⇒ Object
100 |
# File 'lib/rubimc.rb', line 100 def ^(val); common_operator(val, __method__); end |
#c_assign=(val) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubimc.rb', line 57 def common_operator(val, operator_sym, **) if not val.class.respond_to? :to_s RubimCode.perror "Conversion of variable #{val} is impossible. Method 'to_s' not found" else if [: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| ... } ⇒ Object
Range-operators “..” and “…” ToDo: is it need? or use Enumerator?
123 124 125 126 127 128 129 130 |
# 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 ⇒ Object
37 38 39 40 41 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/rubimc.rb', line 33 def to_i self.name.to_i end |
#to_rubim ⇒ Object
43 44 45 |
# File 'lib/rubimc.rb', line 43 def to_rubim self end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/rubimc.rb', line 29 def to_s "(" + self.name + ")" end |
#|(val) ⇒ Object
99 |
# File 'lib/rubimc.rb', line 99 def |(val); common_operator(val, __method__); end |
#~@ ⇒ Object
87 |
# File 'lib/rubimc.rb', line 87 def ~@; common_operator(nil, __method__, unary: true); end |