Class: Code::Object::String
Constant Summary
Constants inherited
from Code::Object
NUMBER_CLASSES
Instance Attribute Summary
Attributes inherited from Code::Object
#raw
Instance Method Summary
collapse
#<=>, #==, as_json, #as_json, call, #code_and_operator, code_and_operator, #code_as_json, code_as_json, code_different, #code_different, #code_equal_equal, code_equal_equal, code_equal_equal_equal, #code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_new, code_or_operator, #code_or_operator, code_self, #code_self, #code_to_json, code_to_json, falsy?, #falsy?, #hash, inspect, maybe, multi_fetch, #multi_fetch, #nothing?, nothing?, repeat, sig, #sig, #succ, #to_code, to_json, #to_json, to_s, truthy?, #truthy?, |
Constructor Details
#initialize(*args, **_kargs) ⇒ String
Returns a new instance of String.
6
7
8
9
10
|
# File 'lib/code/object/string.rb', line 6
def initialize(*args, **_kargs, &)
raw = args.first || Nothing.new
raw = raw.raw if raw.is_a?(Object)
@raw = raw.to_s
end
|
Instance Method Details
#call(**args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/code/object/string.rb', line 12
def call(**args)
code_operator = args.fetch(:operator, nil).to_code
code_arguments = args.fetch(:arguments, List.new).to_code
globals = multi_fetch(args, *GLOBALS)
code_value = code_arguments.code_first
case code_operator.to_s
when "&", "to_function"
sig(args)
code_to_function(**globals)
when "*"
sig(args) { Integer | Decimal }
code_multiplication(code_value)
when "+"
sig(args) { Object }
code_plus(code_value)
when "downcase"
sig(args)
code_downcase
when "include?"
sig(args) { String }
code_include?(code_value)
when "reverse"
sig(args)
code_reverse
else
super
end
end
|
#code_downcase ⇒ Object
42
43
44
|
# File 'lib/code/object/string.rb', line 42
def code_downcase
String.new(raw.downcase)
end
|
#code_include?(value) ⇒ Boolean
46
47
48
49
|
# File 'lib/code/object/string.rb', line 46
def code_include?(value)
code_value = value.to_code
Boolean.new(raw.include?(code_value.raw))
end
|
#code_multiplication(other) ⇒ Object
51
52
53
54
|
# File 'lib/code/object/string.rb', line 51
def code_multiplication(other)
code_other = other.to_code
String.new(raw * code_other.raw)
end
|
#code_plus(other) ⇒ Object
56
57
58
59
|
# File 'lib/code/object/string.rb', line 56
def code_plus(other)
code_other = other.to_code
String.new(raw + code_other.to_s)
end
|
#code_reverse ⇒ Object
61
62
63
|
# File 'lib/code/object/string.rb', line 61
def code_reverse
String.new(raw.reverse)
end
|
#code_to_function(**_globals) ⇒ Object
65
66
67
|
# File 'lib/code/object/string.rb', line 65
def code_to_function(**_globals)
Function.new([{ name: "_" }], "_.#{raw}")
end
|