mobj 1.7.3 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mobj.rb +29 -1
- metadata +3 -2
data/lib/mobj.rb
CHANGED
@@ -7,6 +7,7 @@ module Mobj
|
|
7
7
|
end
|
8
8
|
def null!() self end
|
9
9
|
def nil!() self end
|
10
|
+
def itself() self end
|
10
11
|
end
|
11
12
|
|
12
13
|
class ::Fixnum
|
@@ -41,7 +42,7 @@ module Mobj
|
|
41
42
|
end
|
42
43
|
def attempt(value=:root)
|
43
44
|
Forwarder.new do |name, *args, &block|
|
44
|
-
if self.methods(true).include? name
|
45
|
+
if self.methods(true).include? name ##//use respond to?
|
45
46
|
self.__send__(name, *args, &block)
|
46
47
|
elsif value.is_a?(Proc)
|
47
48
|
value.call([name] + args, &block)
|
@@ -172,6 +173,33 @@ module Mobj
|
|
172
173
|
end
|
173
174
|
|
174
175
|
module HashEx
|
176
|
+
|
177
|
+
def symvert(key_converter = :itself, value_converter = key_converter)
|
178
|
+
each.with_object({}) do |(k,v),o|
|
179
|
+
key = if key_converter.is_a?(Proc)
|
180
|
+
key_converter.call(k, v)
|
181
|
+
elsif k.respond_to?(key_converter.sym)
|
182
|
+
k.__send__(key_converter.sym)
|
183
|
+
else
|
184
|
+
k
|
185
|
+
end
|
186
|
+
|
187
|
+
value = if value_converter.is_a?(Proc)
|
188
|
+
value_converter.arity == 1 ? value_converter.call(v) : value_converter.call(k, v)
|
189
|
+
elsif v.respond_to?(value_converter.sym)
|
190
|
+
v.__send__(value_converter.sym)
|
191
|
+
else
|
192
|
+
v
|
193
|
+
end
|
194
|
+
|
195
|
+
o[key] = value
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def symvert!(key_converter = :itself, value_converter = key_converter)
|
200
|
+
replace(symvert(key_converter, value_converter))
|
201
|
+
end
|
202
|
+
|
175
203
|
def method_missing(name, *args, &block)
|
176
204
|
if name[-1] == '=' && args.size == 1
|
177
205
|
key = name[0...-1].sym
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -92,3 +92,4 @@ signing_key:
|
|
92
92
|
specification_version: 3
|
93
93
|
summary: Helpful utils and extentions
|
94
94
|
test_files: []
|
95
|
+
has_rdoc:
|