Class: Code::Object::String
Constant Summary
Constants inherited
from Code::Object
NUMBER_CLASSES
Instance Attribute Summary
#raw
Instance Method Summary
collapse
#code_new, code_new, maybe, name, #name, repeat, |
#<=>, #==, #as_json, #code_and, #code_as_json, #code_deep_duplicate, #code_different, #code_duplicate, #code_equal_equal, #code_equal_equal_equal, #code_exclamation_point, #code_exclusive_range, #code_falsy?, #code_fetch, code_fetch, #code_get, code_get, #code_inclusive_range, #code_name, #code_or, #code_self, #code_set, code_set, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #sig, #succ, #to_code, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs) ⇒ String
Returns a new instance of String.
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/code/object/string.rb', line 6
def initialize(*args, **_kargs, &)
if args.first.is_an?(Class)
@raw = args.first.raw.name
elsif args.first.is_an?(Object)
@raw = args.first.raw.to_s
elsif args.first.is_a?(::Class)
@raw = args.first.name
elsif args.first
@raw = args.first.to_s
else
@raw = ""
end
end
|
Instance Method Details
#call(**args) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/code/object/string.rb', line 20
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 "first"
sig(args) { Integer.maybe }
code_first(code_value)
when "reverse"
sig(args)
code_reverse
when "parameterize"
sig(args)
code_parameterize
else
super
end
end
|
#code_downcase ⇒ Object
56
57
58
|
# File 'lib/code/object/string.rb', line 56
def code_downcase
String.new(raw.downcase)
end
|
#code_first(n = nil) ⇒ Object
91
92
93
94
95
|
# File 'lib/code/object/string.rb', line 91
def code_first(n = nil)
code_n = n.to_code
code_n = Integer.new(1) if code_n.nothing?
String.new(raw.first(code_n.raw))
end
|
#code_include?(value) ⇒ Boolean
60
61
62
63
|
# File 'lib/code/object/string.rb', line 60
def code_include?(value)
code_value = value.to_code
Boolean.new(raw.include?(code_value.raw))
end
|
#code_inspect ⇒ Object
83
84
85
|
# File 'lib/code/object/string.rb', line 83
def code_inspect
String.new(raw.inspect)
end
|
#code_multiplication(other) ⇒ Object
65
66
67
68
|
# File 'lib/code/object/string.rb', line 65
def code_multiplication(other)
code_other = other.to_code
String.new(raw * code_other.raw)
end
|
#code_parameterize ⇒ Object
87
88
89
|
# File 'lib/code/object/string.rb', line 87
def code_parameterize
String.new(raw.parameterize)
end
|
#code_plus(other) ⇒ Object
70
71
72
73
|
# File 'lib/code/object/string.rb', line 70
def code_plus(other)
code_other = other.to_code
String.new(raw + code_other.to_s)
end
|
#code_reverse ⇒ Object
75
76
77
|
# File 'lib/code/object/string.rb', line 75
def code_reverse
String.new(raw.reverse)
end
|
#code_to_function(**_globals) ⇒ Object
79
80
81
|
# File 'lib/code/object/string.rb', line 79
def code_to_function(**_globals)
Function.new([{ name: "_" }], "_.#{raw}")
end
|