Module: Fable::NativeFunctionOperations

Included in:
NativeFunctionCall
Defined in:
lib/fable/native_function_operations.rb

Instance Method Summary collapse

Instance Method Details

#addition(x, y) ⇒ Object



3
4
5
# File 'lib/fable/native_function_operations.rb', line 3

def addition(x, y)
  return x + y
end

#all(x) ⇒ Object



129
130
131
# File 'lib/fable/native_function_operations.rb', line 129

def all(x)
  x.all
end

#and(x, y) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/fable/native_function_operations.rb', line 59

def and(x,y)
  if x.is_a?(InkList)
    return (x.size > 0 && y.size > 0) ? 1 : 0
  else
    return (x != 0 && y != 0) ? 1 : 0
  end
end

#ceiling(x) ⇒ Object



91
92
93
# File 'lib/fable/native_function_operations.rb', line 91

def ceiling(x)
  x.ceil.to_f
end

#count(x) ⇒ Object



141
142
143
# File 'lib/fable/native_function_operations.rb', line 141

def count(x)
  x.count
end

#divide(x, y) ⇒ Object



15
16
17
# File 'lib/fable/native_function_operations.rb', line 15

def divide(x,y)
  x / y
end

#equal(x, y) ⇒ Object



27
28
29
# File 'lib/fable/native_function_operations.rb', line 27

def equal(x,y)
  return (x == y) ? 1 : 0
end

#float_value(x) ⇒ Object



99
100
101
# File 'lib/fable/native_function_operations.rb', line 99

def float_value(x)
  x.to_f
end

#floor(x) ⇒ Object



87
88
89
# File 'lib/fable/native_function_operations.rb', line 87

def floor(x)
  x.floor.to_f
end

#greater(x, y) ⇒ Object



31
32
33
# File 'lib/fable/native_function_operations.rb', line 31

def greater(x,y)
  return (x > y) ? 1 : 0
end

#greater_than_or_equal(x, y) ⇒ Object



39
40
41
# File 'lib/fable/native_function_operations.rb', line 39

def greater_than_or_equal(x,y)
  return (x >= y) ? 1 : 0
end

#has(x, y) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/fable/native_function_operations.rb', line 103

def has(x,y)
  if x.is_a?(InkList)
    return x.contains?(y) ? 1 : 0
  else
    return x.include?(y) ? 1 : 0
  end
end

#has_not(x, y) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/fable/native_function_operations.rb', line 111

def has_not(x,y)
  has_return = has(x,y)
  # Need to invert values
  if has_return == 0
    return 1
  else
    return 0
  end
end

#int_value(x) ⇒ Object



95
96
97
# File 'lib/fable/native_function_operations.rb', line 95

def int_value(x)
  x.to_i
end

#intersection(x, y) ⇒ Object



121
122
123
# File 'lib/fable/native_function_operations.rb', line 121

def intersection(x,y)
  return x & y
end

#invert(x) ⇒ Object



125
126
127
# File 'lib/fable/native_function_operations.rb', line 125

def invert(x)
  x.inverse
end

#less(x, y) ⇒ Object



35
36
37
# File 'lib/fable/native_function_operations.rb', line 35

def less(x,y)
  return (x < y) ? 1 : 0
end

#less_than_or_equal(x, y) ⇒ Object



43
44
45
# File 'lib/fable/native_function_operations.rb', line 43

def less_than_or_equal(x,y)
  return (x <= y) ? 1 : 0
end

#list_max(x) ⇒ Object



137
138
139
# File 'lib/fable/native_function_operations.rb', line 137

def list_max(x)
  x.max_as_list
end

#list_min(x) ⇒ Object



133
134
135
# File 'lib/fable/native_function_operations.rb', line 133

def list_min(x)
  x.min_as_list
end

#max(x, y) ⇒ Object



75
76
77
# File 'lib/fable/native_function_operations.rb', line 75

def max(x,y)
  return [x,y].max
end

#min(x, y) ⇒ Object



79
80
81
# File 'lib/fable/native_function_operations.rb', line 79

def min(x,y)
  return [x,y].min
end

#modulo(x, y) ⇒ Object



19
20
21
# File 'lib/fable/native_function_operations.rb', line 19

def modulo(x,y)
  return x % y
end

#multiply(x, y) ⇒ Object



11
12
13
# File 'lib/fable/native_function_operations.rb', line 11

def multiply(x,y)
  return x * y
end

#negate(x) ⇒ Object



23
24
25
# File 'lib/fable/native_function_operations.rb', line 23

def negate(x)
  return -x
end

#not(x) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/fable/native_function_operations.rb', line 51

def not(x)
  if x.is_a?(InkList)
    return (x.size == 0) ? 1 : 0
  else
    return (x == 0) ? 1 : 0
  end
end

#not_equal(x, y) ⇒ Object



47
48
49
# File 'lib/fable/native_function_operations.rb', line 47

def not_equal(x,y)
  return (x != y) ? 1 : 0
end

#or(x, y) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/fable/native_function_operations.rb', line 67

def or(x,y)
  if x.is_a?(InkList)
    return (x.size > 0 || y.size > 0) ? 1 : 0
  else
    return (x != 0 || y != 0) ? 1 : 0
  end
end

#pow(x, y) ⇒ Object



83
84
85
# File 'lib/fable/native_function_operations.rb', line 83

def pow(x,y)
  return x ** y
end

#subtraction(x, y) ⇒ Object



7
8
9
# File 'lib/fable/native_function_operations.rb', line 7

def subtraction(x,y)
  return x - y
end

#value_of_list(x) ⇒ Object



145
146
147
# File 'lib/fable/native_function_operations.rb', line 145

def value_of_list(x)
  x.max_item[1]
end