YkLib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/YkLib.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/YkLib/Yk/__advance__.rb +151 -0
- data/lib/YkLib/Yk/__defun__.rb +44 -0
- data/lib/YkLib/Yk/__hook__.rb +244 -0
- data/lib/YkLib/Yk/__minmax__.rb +123 -0
- data/lib/YkLib/Yk/__stdlog.rb +329 -0
- data/lib/YkLib/Yk/adhocLiterals/email.rb +119 -0
- data/lib/YkLib/Yk/adhocLiterals/path.rb +402 -0
- data/lib/YkLib/Yk/adhocLiterals/tag.rb +19 -0
- data/lib/YkLib/Yk/adhocLiterals/url.rb +36 -0
- data/lib/YkLib/Yk/adhocLiterals.rb +199 -0
- data/lib/YkLib/Yk/auto_escseq.rb +5 -0
- data/lib/YkLib/Yk/auto_pstore.rb +179 -0
- data/lib/YkLib/Yk/bsearch.rb +120 -0
- data/lib/YkLib/Yk/clambda.rb +309 -0
- data/lib/YkLib/Yk/confLine.rb +423 -0
- data/lib/YkLib/Yk/create_tty_width_available.rb +24 -0
- data/lib/YkLib/Yk/crypt.rb +26 -0
- data/lib/YkLib/Yk/debug2 +1 -0
- data/lib/YkLib/Yk/debug2.rb +473 -0
- data/lib/YkLib/Yk/debugout.rb +139 -0
- data/lib/YkLib/Yk/email_tz.rb +533 -0
- data/lib/YkLib/Yk/enum_expect.rb +170 -0
- data/lib/YkLib/Yk/errlog.rb +5 -0
- data/lib/YkLib/Yk/escseq.rb +59 -0
- data/lib/YkLib/Yk/eval_alt.rb +281 -0
- data/lib/YkLib/Yk/expector.rb +93 -0
- data/lib/YkLib/Yk/fetch.rb +556 -0
- data/lib/YkLib/Yk/fetch_old.rb +290 -0
- data/lib/YkLib/Yk/fib.rb +158 -0
- data/lib/YkLib/Yk/file_aux.rb +843 -0
- data/lib/YkLib/Yk/file_aux2.rb +919 -0
- data/lib/YkLib/Yk/file_aux_old.rb +160 -0
- data/lib/YkLib/Yk/filemod.rb +19 -0
- data/lib/YkLib/Yk/force_escseq.rb +3 -0
- data/lib/YkLib/Yk/generator__.rb +144 -0
- data/lib/YkLib/Yk/generator__.rb.org +139 -0
- data/lib/YkLib/Yk/indenter/argless_case.rb +46 -0
- data/lib/YkLib/Yk/indenter/each_token.rb +671 -0
- data/lib/YkLib/Yk/indenter/free_case.rb +313 -0
- data/lib/YkLib/Yk/indenter/if_less.rb +53 -0
- data/lib/YkLib/Yk/indenter/independent_ensure.rb +23 -0
- data/lib/YkLib/Yk/indenter/independent_rescue.rb +23 -0
- data/lib/YkLib/Yk/indenter/operand_circumflex.rb +0 -0
- data/lib/YkLib/Yk/indenter/operand_period.rb +16 -0
- data/lib/YkLib/Yk/indenter/parenless_and.rb +37 -0
- data/lib/YkLib/Yk/indenter/post_test.rb +48 -0
- data/lib/YkLib/Yk/indenter/token.rb +1525 -0
- data/lib/YkLib/Yk/indenter.rb +1382 -0
- data/lib/YkLib/Yk/inot.rb +265 -0
- data/lib/YkLib/Yk/intf.rb +815 -0
- data/lib/YkLib/Yk/io_aux.rb +1332 -0
- data/lib/YkLib/Yk/ioctl.rb +60 -0
- data/lib/YkLib/Yk/ipcc.rb +87 -0
- data/lib/YkLib/Yk/ipcountry.rb +207 -0
- data/lib/YkLib/Yk/ipv4adr.rb +318 -0
- data/lib/YkLib/Yk/localmail.rb +276 -0
- data/lib/YkLib/Yk/method_chain.rb +359 -0
- data/lib/YkLib/Yk/misc_tz.rb +1716 -0
- data/lib/YkLib/Yk/missing_method.rb +50 -0
- data/lib/YkLib/Yk/mojiConv.rb +257 -0
- data/lib/YkLib/Yk/nostdlog.rb +4 -0
- data/lib/YkLib/Yk/on_marshal.rb +20 -0
- data/lib/YkLib/Yk/overrider.rb +47 -0
- data/lib/YkLib/Yk/path.rb +293 -0
- data/lib/YkLib/Yk/path_aux.rb +883 -0
- data/lib/YkLib/Yk/path_aux_alt.rb +0 -0
- data/lib/YkLib/Yk/path_rep.rb +1267 -0
- data/lib/YkLib/Yk/pg_setup.rb +917 -0
- data/lib/YkLib/Yk/procinfo.rb +314 -0
- data/lib/YkLib/Yk/proclist.rb +492 -0
- data/lib/YkLib/Yk/property.rb +863 -0
- data/lib/YkLib/Yk/ranger.rb +606 -0
- data/lib/YkLib/Yk/resolv_tz.rb +88 -0
- data/lib/YkLib/Yk/rlprompt.rb +73 -0
- data/lib/YkLib/Yk/rootexec.rb +48 -0
- data/lib/YkLib/Yk/rpm-packageproxy.rb +784 -0
- data/lib/YkLib/Yk/rpm-packageproxy2.rb +1430 -0
- data/lib/YkLib/Yk/rwhen.rb +21 -0
- data/lib/YkLib/Yk/selector.rb +124 -0
- data/lib/YkLib/Yk/set.rb +170 -0
- data/lib/YkLib/Yk/shellquote.rb +300 -0
- data/lib/YkLib/Yk/sio.rb +1001 -0
- data/lib/YkLib/Yk/sio0.rb +835 -0
- data/lib/YkLib/Yk/sio_aux.rb +1524 -0
- data/lib/YkLib/Yk/sio_inot.rb +86 -0
- data/lib/YkLib/Yk/sock_aux.rb +42 -0
- data/lib/YkLib/Yk/spipe.rb +843 -0
- data/lib/YkLib/Yk/sql_table.rb +565 -0
- data/lib/YkLib/Yk/stdlog.rb +4 -0
- data/lib/YkLib/Yk/syscommand.rb +173 -0
- data/lib/YkLib/Yk/sysinit.rb +75 -0
- data/lib/YkLib/Yk/ttyFontWidth.rb +46113 -0
- data/lib/YkLib/Yk/tty_char.dump +0 -0
- data/lib/YkLib/Yk/tty_char.rb +47 -0
- data/lib/YkLib/Yk/tty_char_create.rb +437031 -0
- data/lib/YkLib/Yk/tty_char_static.rb +437016 -0
- data/lib/YkLib/Yk/tty_rewrite.rb +142 -0
- data/lib/YkLib/Yk/tty_str.rb +461 -0
- data/lib/YkLib/Yk/tty_width.dat.rb +114 -0
- data/lib/YkLib/Yk/tty_width.rb +180 -0
- data/lib/YkLib/Yk/tty_width_available +569 -0
- data/lib/YkLib/Yk/tty_width_list +0 -0
- data/lib/YkLib/Yk/tty_width_list.linux +280 -0
- data/lib/YkLib/Yk/tty_width_list.windows +324 -0
- data/lib/YkLib/Yk/tz_tty +0 -0
- data/lib/YkLib/Yk/tz_tty.rb +0 -0
- data/lib/YkLib/Yk/uprepos.rb +94 -0
- data/lib/YkLib/Yk/userinfo.rb +91 -0
- data/lib/YkLib/Yk/with.rb +109 -0
- data/lib/YkLib/version.rb +3 -0
- data/lib/YkLib.rb +6 -0
- metadata +170 -0
@@ -0,0 +1,863 @@
|
|
1
|
+
if RUBY_VERSION >= '2.7'
|
2
|
+
|
3
|
+
require 'Yk/eval_alt'
|
4
|
+
|
5
|
+
|
6
|
+
module Friend
|
7
|
+
FriendList = Hash.new{|h, k| h[k] = Set.new}
|
8
|
+
refine Module do
|
9
|
+
def friend *args
|
10
|
+
binding.of_caller(1).eval("self").class_eval %Q{
|
11
|
+
private
|
12
|
+
if !Friend::FriendList.key? self
|
13
|
+
[#{args.join(', ')}].each do |e|
|
14
|
+
Friend::FriendList[self].add e
|
15
|
+
end
|
16
|
+
def __allow_call? name
|
17
|
+
if [private_methods, protected_methods].find{_1.include?(name)}
|
18
|
+
cls = binding.of_caller(2).eval("self.class")
|
19
|
+
if !self.is_a?(Class)
|
20
|
+
toFind = Friend::FriendList[self.class]
|
21
|
+
else
|
22
|
+
k = Friend::FriendList.keys.find{|e| self.is_a?(e)}
|
23
|
+
toFind = Friend::FriendList[k] if k
|
24
|
+
end
|
25
|
+
found = toFind&.find{|e|
|
26
|
+
c = cls
|
27
|
+
ret = while c && c != Class
|
28
|
+
if e == c
|
29
|
+
break true
|
30
|
+
end
|
31
|
+
c = c.superclass
|
32
|
+
end
|
33
|
+
ret
|
34
|
+
}
|
35
|
+
end
|
36
|
+
found
|
37
|
+
end
|
38
|
+
alias_method :__method_missing_org, :method_missing
|
39
|
+
def method_missing name, *args, **h, &bl
|
40
|
+
# p.red args, h, bl
|
41
|
+
if __allow_call? name
|
42
|
+
method(name).call *args, **h, &bl
|
43
|
+
else
|
44
|
+
__method_missing_org name, *args, **h, &bl
|
45
|
+
end
|
46
|
+
end
|
47
|
+
alias_method :respond_to_missing_org, :respond_to_missing?
|
48
|
+
def respond_to_missing? symbol, include_private
|
49
|
+
__allow_call?(symbol) || respond_to_missing_org(symbol, include_private)
|
50
|
+
end
|
51
|
+
def self.friend *clsList
|
52
|
+
clsList.each{Friend::FriendList[self].add _1}
|
53
|
+
# p FriendList
|
54
|
+
end
|
55
|
+
end
|
56
|
+
}
|
57
|
+
# p FriendList
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
module Misc
|
62
|
+
refine Module do
|
63
|
+
def refine_class cls, &prc
|
64
|
+
c = class << cls; self; end
|
65
|
+
refine c, &prc
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
module Warning
|
73
|
+
def self.warn (msg, category: nil)
|
74
|
+
if msg !~ /redefining Object\#(method_missing|respond_to_missing\?) may cause infinite loop/
|
75
|
+
super(msg)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
module Proc_
|
82
|
+
class Proc_from_LocalVariable < Proc
|
83
|
+
def initialize b, l
|
84
|
+
@binding = b
|
85
|
+
@label = l
|
86
|
+
super()do
|
87
|
+
_
|
88
|
+
end
|
89
|
+
end
|
90
|
+
def _ &bl
|
91
|
+
ret = @binding.local_variable_get(@label)
|
92
|
+
if bl
|
93
|
+
instance_eval(&bl)
|
94
|
+
end
|
95
|
+
ret
|
96
|
+
end
|
97
|
+
def _= arg
|
98
|
+
@binding.local_variable_set(@label, arg)
|
99
|
+
end
|
100
|
+
def pivot
|
101
|
+
@binding.local_variable_get(@label)
|
102
|
+
end
|
103
|
+
def pivot= arg
|
104
|
+
@binding.local_variable_set(@label, arg)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
class Proc_from_MethodLabel < Proc
|
108
|
+
def initialize obj, label, *args, **opts, &bl
|
109
|
+
@label = label
|
110
|
+
@args = args
|
111
|
+
@opts = opts
|
112
|
+
@block = bl
|
113
|
+
@obj = obj
|
114
|
+
super do |*args, **opts, &bl|
|
115
|
+
_ *args, **opts, &bl
|
116
|
+
end
|
117
|
+
end
|
118
|
+
def _ *args, **opts, &bl
|
119
|
+
@obj.method(@label).call(*(@args + args), **(@opts.merge opts), &(bl || @block))
|
120
|
+
end
|
121
|
+
# _{1 < a <= b < 3 <= 5}
|
122
|
+
# _.foo(_{1 or 2})._
|
123
|
+
# _.foo(_{arr})._
|
124
|
+
# _.a
|
125
|
+
# _.a{pivot += 1}
|
126
|
+
def _= *args, **opts, &bl
|
127
|
+
@eqLabel ||= (@label.to_s + "=").intern
|
128
|
+
@obj.method(@eqLabel).call(*(@args + args), **(@opts.merge opts), &(bl || @block))
|
129
|
+
end
|
130
|
+
def pivot *args, **opts, &bl
|
131
|
+
ret = self._(*args, **opts, &bl)
|
132
|
+
method(:_=).call(*args, **opts, &bl)
|
133
|
+
ret
|
134
|
+
end
|
135
|
+
end
|
136
|
+
class Proc_seed < BasicObject
|
137
|
+
def method_missing label, *args, **opts, &bl
|
138
|
+
if @binding && args.empty? && opts.empty? && !bl && @binding.local_variable_defined?(label)
|
139
|
+
Proc_from_LocalVariable.new @binding, label do; end
|
140
|
+
else
|
141
|
+
Proc_from_MethodLabel.new @obj, label, *args, **opts, &bl
|
142
|
+
end
|
143
|
+
end
|
144
|
+
def initialize obj, b = nil
|
145
|
+
@obj = obj
|
146
|
+
@binding = b
|
147
|
+
end
|
148
|
+
end
|
149
|
+
refine Object do
|
150
|
+
private
|
151
|
+
def _
|
152
|
+
Proc_seed.new(self, binding.of_caller(1))
|
153
|
+
end
|
154
|
+
alias_method :__org_method_missing, :method_missing
|
155
|
+
def method_missing label, *args, **opts, &bl
|
156
|
+
if label == :_ #public call
|
157
|
+
Proc_seed.new(self)
|
158
|
+
else
|
159
|
+
__org_method_missing(label, *args, **opts, &bl)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
alias_method :__org_respond_to_missing?, :respond_to_missing?
|
163
|
+
def respond_to_missing? label, priv
|
164
|
+
if label == :_
|
165
|
+
true
|
166
|
+
else
|
167
|
+
__org_respond_to_missing?(label, priv)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
class Proc_from_Label < Proc
|
172
|
+
def initialize label, args, opts, bl
|
173
|
+
super do |obj|
|
174
|
+
obj.method(label).call(*args, **opts, &bl)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
refine Symbol do
|
179
|
+
def call *args, **opts, &bl
|
180
|
+
Proc_from_Label.new self, args, opts, bl
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
module Property
|
186
|
+
class BObject
|
187
|
+
Methods = %W{
|
188
|
+
__send__
|
189
|
+
__id__
|
190
|
+
instance_eval
|
191
|
+
method_missing
|
192
|
+
p
|
193
|
+
pp
|
194
|
+
binding
|
195
|
+
object_id
|
196
|
+
initialize
|
197
|
+
respond_to?
|
198
|
+
caller
|
199
|
+
inspect
|
200
|
+
}
|
201
|
+
instance_methods.each do |m|
|
202
|
+
alias_method ("__call_org_method_of_#{m}_on_BObject__").intern, m
|
203
|
+
if !Methods.include? m.to_s
|
204
|
+
remove_method(m) rescue nil
|
205
|
+
end
|
206
|
+
end
|
207
|
+
private_instance_methods.each do |m|
|
208
|
+
alias_method ("__call_org_method_of_#{m}_on_BObject__").intern, m
|
209
|
+
if !Methods.include? m.to_s
|
210
|
+
remove_method(m) rescue nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
def __call_org_method__ label, *args, **opts, &bl
|
214
|
+
__send__ ("__call_org_method_of_" + label.to_s + "_on_BObject__").intern, *args, **opts, &bl
|
215
|
+
end
|
216
|
+
end
|
217
|
+
%W{start placeHolder get set pivot swap this}.each do |name|
|
218
|
+
Property.module_eval %{
|
219
|
+
module_function
|
220
|
+
def #{name}
|
221
|
+
@@#{name}
|
222
|
+
end
|
223
|
+
def #{name}= sym
|
224
|
+
@@#{name} = sym
|
225
|
+
end
|
226
|
+
}
|
227
|
+
end
|
228
|
+
def property_public_methods
|
229
|
+
%W{get set pivot swap}
|
230
|
+
end
|
231
|
+
module_function :property_public_methods
|
232
|
+
end
|
233
|
+
|
234
|
+
CompChain.seed = [:___, :■, :͐ , :͑ , :͔ , :͕ ]
|
235
|
+
|
236
|
+
# 1 < ■2 == ■3 < 4
|
237
|
+
|
238
|
+
Property.start = [:_, :▲, :̄ ]
|
239
|
+
Property.placeHolder = [:__, :∆, :͝ , :ˬ, "➀➁➂➃➄➅➆➇➈", :͟ ]
|
240
|
+
|
241
|
+
#_①:͝is_a? ,
|
242
|
+
|
243
|
+
#case
|
244
|
+
#when ˬ_e?
|
245
|
+
#when ˬis_a?(Foo)
|
246
|
+
#when s̄in(➀) == 1.0
|
247
|
+
#end
|
248
|
+
|
249
|
+
Property.get = [:_get, :▼]
|
250
|
+
Property.set = [:_set, :◀]
|
251
|
+
Property.pivot = [:_pivot, :◀◀]
|
252
|
+
Property.swap = [:_swap, :◀▶]
|
253
|
+
Property.this = :_
|
254
|
+
|
255
|
+
#
|
256
|
+
|
257
|
+
module Property
|
258
|
+
class Property_base < BObject
|
259
|
+
def coerce a
|
260
|
+
if !Property_base.(a)
|
261
|
+
ag = Property_raw.new(a)
|
262
|
+
else
|
263
|
+
ag = a
|
264
|
+
end
|
265
|
+
[ag, self]
|
266
|
+
end
|
267
|
+
alias_method :__org_method_missing, :method_missing
|
268
|
+
MCheck = {}
|
269
|
+
def method_missing label, *args, **opts, &bl
|
270
|
+
curCall = nil
|
271
|
+
begin
|
272
|
+
if caller(1)[0] =~ /:/
|
273
|
+
curCall = caller(1)[0]
|
274
|
+
if curCall[/^(.*):/, 1] == __FILE__
|
275
|
+
return __org_method_missing(label, *args, **opts, &bl)
|
276
|
+
elsif (require "fiber"; MCheck[Fiber.current] ||= {})[[curCall, label]]
|
277
|
+
MCheck[Fiber.current].delete [curCall, label]
|
278
|
+
return __org_method_missing(label, *args, **opts, &bl)
|
279
|
+
else
|
280
|
+
MCheck[Fiber.current][[curCall, label]] = true
|
281
|
+
end
|
282
|
+
end
|
283
|
+
Property_from_MethodLabelBase.emerge self, label, *args, **opts, &bl
|
284
|
+
ensure
|
285
|
+
(MCheck[Fiber.current] ||= {}).delete([curCall, label]) if curCall
|
286
|
+
end
|
287
|
+
end
|
288
|
+
def respond_to_missing? label, priv
|
289
|
+
true
|
290
|
+
end
|
291
|
+
def === caseArg
|
292
|
+
if caseArg.respond_to?(:__call_org_method__) && caseArg.__call_org_method__(:is_a?, Property_base)
|
293
|
+
caseArg.__Property_get__ __Property_get__
|
294
|
+
else
|
295
|
+
__Property_get__ caseArg
|
296
|
+
end
|
297
|
+
end
|
298
|
+
def to_proc
|
299
|
+
Proc.new do |*args, **opts, &bl|
|
300
|
+
__Property_get__ *args, **opts, &bl
|
301
|
+
end
|
302
|
+
end
|
303
|
+
Property.property_public_methods.each do |m|
|
304
|
+
pm = "__Property_#{m}__".intern
|
305
|
+
define_method pm do |*args, **opts, &bl|
|
306
|
+
__org_method_missing pm, *args, **opts, &bl
|
307
|
+
end
|
308
|
+
mm = Property.method(m.intern).()
|
309
|
+
if pm != mm
|
310
|
+
class_eval %{
|
311
|
+
def #{mm} (...)
|
312
|
+
#{pm}(...)
|
313
|
+
end
|
314
|
+
}
|
315
|
+
end
|
316
|
+
end
|
317
|
+
class_eval %{
|
318
|
+
def #{Property.this} (...)
|
319
|
+
__Property_get__(...)
|
320
|
+
end
|
321
|
+
def #{Property.this}= (...)
|
322
|
+
__Property_set__(...)
|
323
|
+
end
|
324
|
+
}
|
325
|
+
def __Property_pivot__ *args, &bl
|
326
|
+
ret = __Property_get__
|
327
|
+
__Property_set__ *args, &bl
|
328
|
+
ret
|
329
|
+
end
|
330
|
+
def __Property_this__= *args
|
331
|
+
__Property_set__ *args
|
332
|
+
__Property_get__
|
333
|
+
end
|
334
|
+
def __Property_swap__ b
|
335
|
+
if !b.respond_to?(:__call_org_method__) || !b.__call_org_method__(:is_a?, Property_base)
|
336
|
+
raise ArgumentError.new("#{b.inspect} is not a property")
|
337
|
+
end
|
338
|
+
tmp = __Property_get__
|
339
|
+
__Property_set__ b.__Property_get__
|
340
|
+
b.__Property_set__ tmp
|
341
|
+
[__Property_get__, b.__Property_get__]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
class Property_from_Constant < Property_base
|
345
|
+
def initialize b, l
|
346
|
+
@binding = b
|
347
|
+
@label = l
|
348
|
+
end
|
349
|
+
def __Property_get__ (...)
|
350
|
+
@binding.eval(@label)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
class Property_from_LocalVariable < Property_base
|
354
|
+
def initialize b, l
|
355
|
+
@binding = b
|
356
|
+
@label = l
|
357
|
+
end
|
358
|
+
def __Property_get__ (...)
|
359
|
+
@binding.local_variable_get(@label)
|
360
|
+
end
|
361
|
+
def __Property_set__ *args, &bl
|
362
|
+
if !args.empty?
|
363
|
+
if !bl
|
364
|
+
@binding.local_variable_set @label, (args.size == 1 ? args[0] : args)
|
365
|
+
else
|
366
|
+
raise ArgumentError("Called with both arguments and block.")
|
367
|
+
end
|
368
|
+
else
|
369
|
+
if bl
|
370
|
+
tmp = @binding.local_variable_get @label
|
371
|
+
@binding.local_variable_set @label, bl.call(tmp)
|
372
|
+
else
|
373
|
+
raise ArgumentError("Called without arguments nor block")
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
class Property_from_LocalVariableSetter < Property_base
|
379
|
+
def initialize b, l, *args
|
380
|
+
@binding = b
|
381
|
+
@label = l
|
382
|
+
@args = ags
|
383
|
+
end
|
384
|
+
def __Property_get__ (...)
|
385
|
+
if @args.size == 1
|
386
|
+
@binding.local_variable_set(@label, @args[0])
|
387
|
+
elsif @args.size >= 2
|
388
|
+
@binding.local_variable_set(@label, @args)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
class Property_raw < Property_base
|
393
|
+
def initialize obj
|
394
|
+
@obj = obj
|
395
|
+
end
|
396
|
+
def __Property_get__ (...)
|
397
|
+
if @obj.respond_to?(:__call_org_method__) && @obj.__call_org_method__(:is_a?, Property_base)
|
398
|
+
@obj.__Property_get__(...)
|
399
|
+
else
|
400
|
+
@obj
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
#case _(:@obj).__call_org_method__(:is_a?, __1)
|
405
|
+
#when __1.Property_callArgProvider
|
406
|
+
# ...
|
407
|
+
#end
|
408
|
+
#case Property_callArgProvider
|
409
|
+
#when _(:@obj).__call_org_method__(:is_a?, __1)
|
410
|
+
# ...
|
411
|
+
#end
|
412
|
+
class Property_from_MethodLabelBase < Property_base
|
413
|
+
DoEval = %{
|
414
|
+
noa = ->o{
|
415
|
+
case o.size
|
416
|
+
when 0
|
417
|
+
nil
|
418
|
+
when 1
|
419
|
+
o[0]
|
420
|
+
else
|
421
|
+
o
|
422
|
+
end
|
423
|
+
}
|
424
|
+
if @obj.respond_to?(:__call_org_method__) && (
|
425
|
+
if @obj.__call_org_method__(:is_a?, Property::Property_callArgProvider)
|
426
|
+
obj = noa.(@obj.__Property_get__(*args, **opts, &block))
|
427
|
+
elsif @obj.__call_org_method__(:is_a?, Property::Property_base)
|
428
|
+
obj = @obj.__Property_get__(*args, **opts, &block)
|
429
|
+
end)
|
430
|
+
else
|
431
|
+
obj = @obj
|
432
|
+
end
|
433
|
+
}.l
|
434
|
+
DoEvalAll = %{
|
435
|
+
#{DoEval.l}
|
436
|
+
eargs = []
|
437
|
+
@args.each{|e|
|
438
|
+
if e.respond_to?(:__call_org_method__) && (
|
439
|
+
if e.__call_org_method__(:is_a?, Property::Property_callArgProvider_to_a)
|
440
|
+
p
|
441
|
+
eargs.push *e.__Property_get__(*args, **opts, &block)
|
442
|
+
elsif e.__call_org_method__(:is_a?, Property::Property_callArgProvider)
|
443
|
+
p eargs
|
444
|
+
eargs.push *e.__Property_get__(*args, **opts, &block)
|
445
|
+
p eargs
|
446
|
+
elsif e.__call_org_method__(:is_a?, Property::Property_base)
|
447
|
+
p
|
448
|
+
eargs.push e.__Property_get__(*args, **opts, &block)
|
449
|
+
end)
|
450
|
+
else
|
451
|
+
eargs.push e
|
452
|
+
end
|
453
|
+
}
|
454
|
+
if @opts
|
455
|
+
eopts = {}
|
456
|
+
@opts.each do |k, v|
|
457
|
+
if k.respond_to?(:__call_org_method__) && k.__call_org_method__(:is_a?, Property_callArgProvider_to_hash) && v == nil
|
458
|
+
eopts.merge k.__Property_get__(*args, **opts, &block)
|
459
|
+
else
|
460
|
+
if v.respond_to?(:__call_org_method__)
|
461
|
+
if v.__call_org_method__(:is_a?, Property::Property_callArgProvider)
|
462
|
+
vc = noa.(v.__Property_get__(*args, **opts, &block))
|
463
|
+
elsif v.__call_org_method__(:is_a?, Property::Property_base)
|
464
|
+
vc = v.__Property_get__(*args, **opts, &block)
|
465
|
+
end
|
466
|
+
end
|
467
|
+
vc ||= v
|
468
|
+
if k.respond_to?(:__call_org_method__)
|
469
|
+
if k.__call_org_method__(:is_a?, Property::Property_callArgProvider)
|
470
|
+
kc = noa.(k.__Property_get__(*args, **opts, &block))
|
471
|
+
elsif k.__call_org_method__(:is_a?, Property::Property_base)
|
472
|
+
kc = k.__Property_get__(*args, **opts, &block)
|
473
|
+
end
|
474
|
+
end
|
475
|
+
kc ||= k
|
476
|
+
eopts[kc] = vc
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
if @block
|
481
|
+
if @block.respond_to?(:__call_org_method__) && (
|
482
|
+
if @block.__call_org_method__(:is_a?, Property::Property_callArgProvider_to_proc)
|
483
|
+
eblock = @block.__Property_get__(*args, **opts, &block)
|
484
|
+
elsif @block.__call_org_method__(:is_a?, Property::Property_callArgProvider)
|
485
|
+
eblock = noa.(@block.__Property_get__(*args, **opts, &block))
|
486
|
+
elsif @block.__call_org_method__(:is_a?, Property::Property_base)
|
487
|
+
eblock = @block.__Property_get__(*args, **opts, &block)
|
488
|
+
end)
|
489
|
+
else
|
490
|
+
eblock = @block
|
491
|
+
end
|
492
|
+
end
|
493
|
+
}.l
|
494
|
+
def self.emerge obj, label, *args, **opts, &bl
|
495
|
+
if label == :[] && !bl
|
496
|
+
Property_from_SubscriptGetterMethodLabel.new obj, *args, **opts
|
497
|
+
elsif args.empty? && opts.empty? && !bl && label[-1] != "="
|
498
|
+
Property_from_GetterMethodLabel.new obj, label
|
499
|
+
else
|
500
|
+
Property_from_MethodLabel.new obj, label, *args, **opts, &bl
|
501
|
+
end
|
502
|
+
end
|
503
|
+
end
|
504
|
+
class Property_from_MethodLabel < Property_from_MethodLabelBase
|
505
|
+
def initialize obj, label, *args, **opts, &bl
|
506
|
+
@label = label
|
507
|
+
@args = args
|
508
|
+
@opts = opts
|
509
|
+
@block = bl
|
510
|
+
@obj = obj
|
511
|
+
end
|
512
|
+
x = %{
|
513
|
+
def __Property_get__ (*args, **opts, &block)
|
514
|
+
p args
|
515
|
+
#{DoEvalAll.l}
|
516
|
+
p eargs
|
517
|
+
obj.method(@label).call(*eargs, **eopts, &eblock)
|
518
|
+
end
|
519
|
+
}.l
|
520
|
+
class_eval x
|
521
|
+
end
|
522
|
+
class Property_from_MethodLabel_PropertyBase < Property_from_MethodLabelBase
|
523
|
+
def __Property_set__ args, bl
|
524
|
+
if !args.empty?
|
525
|
+
if bl
|
526
|
+
raise ArgumentError.new("Cannot use both arguments and block")
|
527
|
+
else
|
528
|
+
yield *args
|
529
|
+
end
|
530
|
+
else
|
531
|
+
if bl
|
532
|
+
yield instance_eval(&bl)
|
533
|
+
else
|
534
|
+
raise ArgumentError.new("Cannot use both arguments and block")
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
539
|
+
class Property_from_GetterMethodLabel < Property_from_MethodLabel_PropertyBase
|
540
|
+
def initialize obj, label
|
541
|
+
@label = label
|
542
|
+
@obj = obj
|
543
|
+
end
|
544
|
+
class_eval %{
|
545
|
+
def __Property_get__ *args, **opts, &block
|
546
|
+
#{DoEval.l}
|
547
|
+
obj.method(@label).call
|
548
|
+
end
|
549
|
+
def __Property_set__ *args, **opts, &block
|
550
|
+
@eqLabel ||= (@label.to_s + "=").intern
|
551
|
+
#{DoEval.l}
|
552
|
+
super args, block do |*eargs|
|
553
|
+
obj.method(@eqLabel).call(*eargs)
|
554
|
+
end
|
555
|
+
end
|
556
|
+
}.l
|
557
|
+
end
|
558
|
+
class Property_from_SubscriptGetterMethodLabel < Property_from_MethodLabel_PropertyBase
|
559
|
+
def initialize obj, *args, **opts
|
560
|
+
@obj = obj
|
561
|
+
@args = args
|
562
|
+
@opts = opts
|
563
|
+
end
|
564
|
+
class_eval %{
|
565
|
+
def __Property_get__ *args, **opts, &block
|
566
|
+
#{DoEvalAll.l}
|
567
|
+
obj.[](*eargs, **eopts)
|
568
|
+
end
|
569
|
+
def __Property_set__ *args, **opts, &block
|
570
|
+
#{DoEvalAll.l}
|
571
|
+
p eargs
|
572
|
+
p args
|
573
|
+
p eopts
|
574
|
+
p block
|
575
|
+
if !args.empty?
|
576
|
+
if !block
|
577
|
+
obj.[]=(*eargs, *args, **eopts)
|
578
|
+
return
|
579
|
+
end
|
580
|
+
elsif block
|
581
|
+
op = block.call(obj.[](*eargs, **eopts))
|
582
|
+
p op
|
583
|
+
obj.[]=(*eargs, op, **eopts)
|
584
|
+
return
|
585
|
+
end
|
586
|
+
raise ArgumentError.new("operand missing or too many operands")
|
587
|
+
end
|
588
|
+
}.l
|
589
|
+
end
|
590
|
+
|
591
|
+
class Property_seed < BObject
|
592
|
+
def method_missing label, *args, **opts, &bl
|
593
|
+
ret = nil
|
594
|
+
if label[-1] != "="
|
595
|
+
if args.empty? && opts.empty? && !bl
|
596
|
+
if @binding.local_variable_defined?(label)
|
597
|
+
ret = Property_from_LocalVariable.new(@binding, label)
|
598
|
+
elsif @binding.eval("Module.constants").include?(label)
|
599
|
+
ret = Property_from_Constant.new(@binding, label)
|
600
|
+
end
|
601
|
+
end
|
602
|
+
ret ||= Property_from_MethodLabelBase.emerge @obj, label, *args, **opts, &bl
|
603
|
+
else
|
604
|
+
labelPre = label.to_s.chop.intern
|
605
|
+
if args.empty? && opts.empty? && bl
|
606
|
+
if @binding.local_variable_defined?(labelPre)
|
607
|
+
ret = Property_from_LocalVariableSetter.new(@binding, labelPre, *args)
|
608
|
+
elsif @binding.eval("Module.constants").include?(labelPre)
|
609
|
+
raise ArgumentError.new("Cannot reinitialize constant")
|
610
|
+
end
|
611
|
+
end
|
612
|
+
ret ||= Property_from_MethodLabelBase.emerge @obj, label, *args
|
613
|
+
end
|
614
|
+
ret
|
615
|
+
end
|
616
|
+
def respond_to_missing? label, priv
|
617
|
+
true
|
618
|
+
end
|
619
|
+
def initialize obj, b = nil
|
620
|
+
@obj = obj
|
621
|
+
@binding = b
|
622
|
+
end
|
623
|
+
end
|
624
|
+
class Prperty_seed_unboundMethod < Property_seed
|
625
|
+
def method_missing label, *args, **opts, &bl
|
626
|
+
Property_from_MethodLabelBase.new Property_callArgProvider.new(1), label, *args, **opts, &bl
|
627
|
+
end
|
628
|
+
def initialize
|
629
|
+
end
|
630
|
+
def to_a
|
631
|
+
Property_callArgProvider_to_a.new
|
632
|
+
end
|
633
|
+
def to_hash
|
634
|
+
Property_callArgProvider_to_hash.new
|
635
|
+
end
|
636
|
+
def to_proc
|
637
|
+
Property_callArgProvider_to_proc.new
|
638
|
+
end
|
639
|
+
end
|
640
|
+
class Property_callArgProvider < Property_base
|
641
|
+
def initialize *args
|
642
|
+
@arg_indexes = []
|
643
|
+
@opt_list = []
|
644
|
+
@all_opts = false
|
645
|
+
@add_block = false
|
646
|
+
@all = false
|
647
|
+
p args
|
648
|
+
args.each do |e|
|
649
|
+
case e
|
650
|
+
when Integer
|
651
|
+
if e >= 1
|
652
|
+
@arg_indexes.push e - 1
|
653
|
+
else
|
654
|
+
@arg_indexes.push e
|
655
|
+
end
|
656
|
+
when Symbol, String
|
657
|
+
case e.to_s
|
658
|
+
when /^\d+$/
|
659
|
+
i = e.to_s.to_i
|
660
|
+
if i >= 1
|
661
|
+
i -= 1
|
662
|
+
end
|
663
|
+
@arg_indexes.push i
|
664
|
+
when "**"
|
665
|
+
@all_opts = true
|
666
|
+
when "*"
|
667
|
+
@arg_indexes.push :all
|
668
|
+
when "&"
|
669
|
+
@add_block = true
|
670
|
+
when "..."
|
671
|
+
@arg_indexes.push :all
|
672
|
+
@all_opts = true
|
673
|
+
@add_block = true
|
674
|
+
else
|
675
|
+
e = e.to_sym
|
676
|
+
@opt_list.push e if !@opt_list.index(e)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
end
|
680
|
+
end
|
681
|
+
def __Property_get__ *args, **opts, &bl
|
682
|
+
rargs = []
|
683
|
+
rbl = bl if @add_block
|
684
|
+
p @arg_indexes, args
|
685
|
+
@arg_indexes.each do |e|
|
686
|
+
if e == :all
|
687
|
+
if !rargs.empty?
|
688
|
+
rargs.push *args
|
689
|
+
end
|
690
|
+
elsif e >= 0
|
691
|
+
rargs.push args[e] if e < args.size
|
692
|
+
else
|
693
|
+
rargs.push args[e] if e >= -args.size
|
694
|
+
end
|
695
|
+
end
|
696
|
+
p rargs
|
697
|
+
if @all_opts
|
698
|
+
ropts = opts
|
699
|
+
else
|
700
|
+
ropts = {}
|
701
|
+
@opt_list.each do |k|
|
702
|
+
if opts.key? k
|
703
|
+
ropts[k] = opts[k]
|
704
|
+
end
|
705
|
+
end
|
706
|
+
end
|
707
|
+
ret = []
|
708
|
+
ret += rargs
|
709
|
+
p ret
|
710
|
+
ret.push ropts if !ropts.empty?
|
711
|
+
ret.push rbl if rbl
|
712
|
+
p ropts
|
713
|
+
p rbl
|
714
|
+
p ret
|
715
|
+
ret
|
716
|
+
end
|
717
|
+
def to_a
|
718
|
+
[Property_callArgProvider_to_a.new(self)]
|
719
|
+
end
|
720
|
+
def to_hash
|
721
|
+
{Property_callArgProvider_to_hash.new(self) => nil}
|
722
|
+
end
|
723
|
+
def to_proc
|
724
|
+
Property_callArgProvider_to_proc.new(self)
|
725
|
+
end
|
726
|
+
end
|
727
|
+
module Property_callArgProvider_to
|
728
|
+
def initialize provider
|
729
|
+
@provider = provider
|
730
|
+
end
|
731
|
+
end
|
732
|
+
class Property_callArgProvider_to_a < Property_base
|
733
|
+
def Property_callArgProvider_to_a;end
|
734
|
+
include Property_callArgProvider_to
|
735
|
+
def __Property_get__ *args, **opts, &bl
|
736
|
+
@provider.__Property_get__ *args, **opts, &bl
|
737
|
+
end
|
738
|
+
end
|
739
|
+
class Property_callArgProvider_to_hash < Property_base
|
740
|
+
def Property_callArgProvider_to_hash;end
|
741
|
+
include Property_callArgProvider_to
|
742
|
+
def __Property_get__ *args, **opts, &bl
|
743
|
+
r = @provider.__Property_get__ *args, **opts, &bl
|
744
|
+
if !r.empty? && r[0].is_a?(Hash) && !r[0].empty?
|
745
|
+
r[0]
|
746
|
+
else
|
747
|
+
{}
|
748
|
+
end
|
749
|
+
end
|
750
|
+
end
|
751
|
+
class Property_callArgProvider_to_proc < Proc
|
752
|
+
def Property_callArgProvider_to_proc;end
|
753
|
+
def initialize provider
|
754
|
+
@provider = provider
|
755
|
+
super do;end
|
756
|
+
end
|
757
|
+
def __Property_get__ *args, **opts, &bl
|
758
|
+
r = @provider.__Property_get__ &bl
|
759
|
+
if !r.empty? && r[0].is_a?(Proc)
|
760
|
+
r[0]
|
761
|
+
else
|
762
|
+
nil
|
763
|
+
end
|
764
|
+
end
|
765
|
+
end
|
766
|
+
refine Kernel do
|
767
|
+
# x = _.a[1]
|
768
|
+
# x._ += 1
|
769
|
+
# x.get
|
770
|
+
# x.set(100)
|
771
|
+
# x.set{_ + 100}
|
772
|
+
# x.pivot(100)
|
773
|
+
# x.pivot{_ + 100}
|
774
|
+
# call(_.a + _{0 or 1} + c)
|
775
|
+
module_function
|
776
|
+
module_eval %{
|
777
|
+
module_function
|
778
|
+
def #{Property.start} arg = nil
|
779
|
+
if !arg
|
780
|
+
Property::Property_seed.new(self, binding.of_caller(1))
|
781
|
+
else
|
782
|
+
case arg.respond_to?(:ruby_symbol) && arg.ruby_symbol
|
783
|
+
when :class_variable
|
784
|
+
Property::Property_from_ClassVariable.new(b, self)
|
785
|
+
when :instance_variable
|
786
|
+
Property::Property_from_InstanceVariable.new(b, self)
|
787
|
+
when :capitalized_symbol
|
788
|
+
if b.eval("Module.constants").include?(self)
|
789
|
+
Property::Property_from_Constant.new(b, self)
|
790
|
+
else
|
791
|
+
Property::Property_from_MethodLabelBase.emerge b.eval("self"), self
|
792
|
+
end
|
793
|
+
when :non_capitalized_symbol
|
794
|
+
if b.local_variable_defined?(self)
|
795
|
+
Property::Property_from_LocalVariable.new(b, self)
|
796
|
+
else
|
797
|
+
Property::Property_from_MethodLabelBase.emerge b.eval("self"), self
|
798
|
+
end
|
799
|
+
else
|
800
|
+
raise ArgumentError("\#{arg}.inspect is not a symbol or not a compatible symbol to ruby")
|
801
|
+
end
|
802
|
+
end
|
803
|
+
end
|
804
|
+
module_function
|
805
|
+
def #{Property.placeHolder} *args
|
806
|
+
if args.empty?
|
807
|
+
Property::Prperty_seed_unboundMethod.new
|
808
|
+
else
|
809
|
+
Property::Property_callArgProvider.new *args
|
810
|
+
end
|
811
|
+
end
|
812
|
+
1.upto 9 do |i|
|
813
|
+
module_eval %{
|
814
|
+
module_function
|
815
|
+
def #{Property.placeHolder}\#{i}
|
816
|
+
Property::Property_callArgProvider.new \#{i}
|
817
|
+
end
|
818
|
+
}
|
819
|
+
end
|
820
|
+
}.l
|
821
|
+
# (_.a(__(1)) * __(:a) * __('...')).foo &__(:&))
|
822
|
+
end
|
823
|
+
refine Symbol do
|
824
|
+
class RubySymbol
|
825
|
+
def ruby_symbol sym
|
826
|
+
case sym.to_s
|
827
|
+
when /^\@\@/
|
828
|
+
if (self.class.class_variable_set(sym, 1) rescue nil)
|
829
|
+
return :class_variable
|
830
|
+
end
|
831
|
+
when /^\@/
|
832
|
+
if (instance_variable_set(sym, 1) rescue nil)
|
833
|
+
return :instance_variable
|
834
|
+
end
|
835
|
+
else
|
836
|
+
if (self.class.const_defined?(sym) || (self.class.const_set(sym, 1)) rescue nil)
|
837
|
+
return :capitalized_symbol
|
838
|
+
end
|
839
|
+
if (binding.local_variable_set(sym) rescue nil)
|
840
|
+
return :non_capitalized_symbol
|
841
|
+
end
|
842
|
+
end
|
843
|
+
nil
|
844
|
+
end
|
845
|
+
TestSymbol = self.new
|
846
|
+
def self.ruby_symbol sym
|
847
|
+
TestSymbol.ruby_symbol sym
|
848
|
+
end
|
849
|
+
end
|
850
|
+
def self.ruby_symbol sym
|
851
|
+
RubySymbol.ruby_symbol sym
|
852
|
+
end
|
853
|
+
def self.for_ruby_local_variable?
|
854
|
+
ruby_symbol == :non_capitalized_symbol
|
855
|
+
end
|
856
|
+
def self.for_ruby_constant?
|
857
|
+
ruby_symbol == :capitalized_symbol
|
858
|
+
end
|
859
|
+
end
|
860
|
+
end
|
861
|
+
|
862
|
+
|
863
|
+
|