tbpgr_utils 0.0.150 → 0.0.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +9 -9
- data/README.md +95 -32
- data/lib/attr_enumerable/attr_enumerable_helper.rb +52 -52
- data/lib/attr_enumerable/map_attr.rb +1 -1
- data/lib/eval_helper/attr_accessor_init_code.rb +3 -3
- data/lib/eval_helper/each_do_code.rb +26 -26
- data/lib/eval_helper/each_with_index_do_code.rb +26 -26
- data/lib/eval_helper/require_code.rb +1 -1
- data/lib/eval_helper/require_relative_code.rb +1 -1
- data/lib/eval_helper/set_variable_code.rb +1 -1
- data/lib/eval_helper/set_variables_code.rb +1 -1
- data/lib/eval_helper/times_code.rb +1 -1
- data/lib/ghostable.rb +1 -1
- data/lib/open_classes/array.rb +0 -2
- data/lib/open_classes/array/average.rb +17 -17
- data/lib/open_classes/array/gte_gte.rb +1 -1
- data/lib/open_classes/array/to_table.rb +1 -1
- data/lib/open_classes/array/together_clear.rb +24 -24
- data/lib/open_classes/array/together_compact.rb +44 -44
- data/lib/open_classes/array/together_empty.rb +1 -1
- data/lib/open_classes/array/together_include.rb +1 -1
- data/lib/open_classes/enumerable.rb +4 -0
- data/lib/open_classes/enumerable/if_else_map.rb +12 -0
- data/lib/open_classes/{array → enumerable}/kernel_send.rb +15 -15
- data/lib/open_classes/{array → enumerable}/sum.rb +3 -3
- data/lib/open_classes/hash/gte_gte.rb +45 -45
- data/lib/open_classes/integer/each_digit.rb +13 -13
- data/lib/open_classes/integer/each_digit_with_index.rb +13 -13
- data/lib/open_classes/integer/reverse_each_digit.rb +13 -13
- data/lib/open_classes/kernel/aa_ancestors.rb +1 -1
- data/lib/open_classes/numeric/is_ascii.rb +4 -4
- data/lib/open_classes/object/any_of.rb +1 -2
- data/lib/open_classes/object/to_bool.rb +1 -1
- data/lib/open_classes/string/ascii_unicode_html_table.rb +1 -1
- data/lib/open_classes/string/ascii_unicode_table.rb +1 -1
- data/lib/open_classes/string/is_meta_variable.rb +7 -7
- data/lib/open_classes/string/justify_table.rb +2 -2
- data/lib/open_classes/string/surround.rb +2 -2
- data/lib/open_classes/symbol/is_meta_variable.rb +6 -6
- data/lib/tbpgr_utils.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/lib/templatable.rb +1 -1
- data/rubocop-todo.yml +2 -36
- data/spec/attr_enumerable/each_attr_spec.rb +1 -1
- data/spec/attr_enumerable/each_attr_with_index_spec.rb +1 -1
- data/spec/attr_enumerable/first_attr_spec.rb +107 -107
- data/spec/attr_enumerable/include_attr_spec.rb +4 -4
- data/spec/attr_enumerable/last_attr_spec.rb +4 -4
- data/spec/attr_enumerable/map_attr_spec.rb +3 -3
- data/spec/attr_enumerable/reduce_attr_spec.rb +3 -3
- data/spec/attr_enumerable/reverse_attr_spec.rb +1 -1
- data/spec/attr_enumerable/sample_attr_spec.rb +3 -3
- data/spec/attr_enumerable/select_attr_spec.rb +2 -2
- data/spec/attr_enumerable/shuffle_attr_spec.rb +1 -1
- data/spec/attr_enumerable/slice_attr_spec.rb +1 -1
- data/spec/attributes_hashable_spec.rb +1 -1
- data/spec/attributes_initializable_spec.rb +21 -21
- data/spec/eval_helper/attr_accessor_init_code_spec.rb +1 -1
- data/spec/eval_helper/attr_init_class_code_spec.rb +1 -1
- data/spec/eval_helper/each_brace_code_spec.rb +2 -2
- data/spec/eval_helper/each_do_code_spec.rb +1 -1
- data/spec/eval_helper/each_with_index_brace_code_spec.rb +2 -2
- data/spec/eval_helper/each_with_index_do_code_spec.rb +2 -2
- data/spec/eval_helper/if_code_after_spec.rb +3 -3
- data/spec/eval_helper/if_code_spec.rb +3 -3
- data/spec/eval_helper/require_code_spec.rb +3 -3
- data/spec/eval_helper/require_relative_code_spec.rb +3 -3
- data/spec/eval_helper/set_variable_code_spec.rb +3 -3
- data/spec/{set_variables_code_spec.rb → eval_helper/set_variables_code_spec.rb} +15 -15
- data/spec/eval_helper/ternary_operator_spec.rb +5 -5
- data/spec/eval_helper/times_code_spec.rb +1 -1
- data/spec/eval_helper/unless_code_after_spec.rb +3 -3
- data/spec/eval_helper/unless_code_spec.rb +3 -3
- data/spec/familyable/familyable_spec.rb +6 -6
- data/spec/ghostable_spec.rb +5 -5
- data/spec/markdown/backquotes_spec.rb +4 -4
- data/spec/markdown/bold_spec.rb +4 -4
- data/spec/markdown/code_spec.rb +3 -3
- data/spec/markdown/codes_spec.rb +2 -2
- data/spec/markdown/heading_spec.rb +5 -5
- data/spec/markdown/hr_spec.rb +1 -1
- data/spec/markdown/italic_spec.rb +4 -4
- data/spec/markdown/link_spec.rb +1 -1
- data/spec/markdown/ol_spec.rb +3 -3
- data/spec/markdown/ul_spec.rb +3 -3
- data/spec/metasyntactic_variable_spec.rb +4 -4
- data/spec/open_classes/array/average_spec.rb +4 -4
- data/spec/open_classes/array/exchange_spec.rb +6 -6
- data/spec/open_classes/array/gte_gte_spec.rb +4 -4
- data/spec/open_classes/array/to_html_table_spec.rb +3 -3
- data/spec/open_classes/array/to_table_spec.rb +2 -2
- data/spec/open_classes/array/together_at_spec.rb +4 -4
- data/spec/open_classes/array/together_clear_spec.rb +3 -3
- data/spec/open_classes/array/together_compact_spec.rb +6 -6
- data/spec/open_classes/array/together_concat_spec.rb +3 -3
- data/spec/open_classes/array/together_delete_at_spec.rb +5 -5
- data/spec/open_classes/array/together_delete_if_spec.rb +4 -4
- data/spec/open_classes/array/together_delete_spec.rb +5 -5
- data/spec/open_classes/array/together_empty_spec.rb +4 -4
- data/spec/open_classes/array/together_fill_spec.rb +5 -5
- data/spec/open_classes/array/together_first_spec.rb +6 -6
- data/spec/open_classes/array/together_include_spec.rb +8 -8
- data/spec/open_classes/array/together_index_spec.rb +5 -5
- data/spec/open_classes/array/together_insert_spec.rb +5 -5
- data/spec/open_classes/array/together_last_spec.rb +6 -6
- data/spec/open_classes/array/together_map_spec.rb +14 -14
- data/spec/open_classes/array/together_pop_spec.rb +8 -8
- data/spec/open_classes/array/together_reduce_spec.rb +8 -8
- data/spec/open_classes/array/together_reverse_spec.rb +119 -119
- data/spec/open_classes/array/together_sample_spec.rb +8 -8
- data/spec/open_classes/array/together_select_spec.rb +6 -6
- data/spec/open_classes/array/together_shift_spec.rb +8 -8
- data/spec/open_classes/array/together_shuffle_spec.rb +3 -3
- data/spec/open_classes/array/together_slice_spec.rb +5 -5
- data/spec/open_classes/array/together_spec.rb +3 -3
- data/spec/open_classes/array/together_with_index_spec.rb +3 -3
- data/spec/open_classes/array/uniq_size_spec.rb +4 -4
- data/spec/open_classes/enumerable/if_else_map_spec.rb +45 -0
- data/spec/open_classes/{array → enumerable}/kernel_send_spec.rb +50 -43
- data/spec/open_classes/{array → enumerable}/sum_spec.rb +8 -2
- data/spec/open_classes/fixnum/to_fixnum_html_table_spec.rb +1 -1
- data/spec/open_classes/fixnum/to_fixnum_table_spec.rb +1 -1
- data/spec/open_classes/hash/gte_gte_spec.rb +4 -4
- data/spec/open_classes/hash/html_table_spec.rb +2 -2
- data/spec/open_classes/hash/table_spec.rb +2 -2
- data/spec/open_classes/integer/each_digit_spec.rb +2 -2
- data/spec/open_classes/integer/each_digit_with_index_spec.rb +2 -2
- data/spec/open_classes/integer/palindromic_prime_spec.rb +6 -6
- data/spec/open_classes/integer/reverse_each_digit_spec.rb +2 -2
- data/spec/open_classes/kernel/aa_ancestors_spec.rb +1 -1
- data/spec/open_classes/kernel/booleans_spec.rb +1 -1
- data/spec/open_classes/kernel/bulk_define_methods_spec.rb +5 -5
- data/spec/open_classes/kernel/bulk_puts_eval_spec.rb +1 -1
- data/spec/open_classes/kernel/evalb_spec.rb +2 -2
- data/spec/open_classes/kernel/exchange_spec.rb +2 -2
- data/spec/open_classes/kernel/hash_to_attributes_spec.rb +3 -3
- data/spec/open_classes/kernel/null_spec.rb +1 -1
- data/spec/open_classes/kernel/print_eval_spec.rb +3 -3
- data/spec/open_classes/kernel/puts_eval_spec.rb +3 -3
- data/spec/open_classes/module_spec.rb +3 -3
- data/spec/open_classes/numeric/dice_back_spec.rb +8 -8
- data/spec/open_classes/numeric/dozen_spec.rb +4 -4
- data/spec/open_classes/numeric/is_ascii_spec.rb +6 -6
- data/spec/open_classes/numeric/to_binary_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_binary_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_digit_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_digit_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_hex_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_hex_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_oct_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_oct_table_spec.rb +1 -1
- data/spec/open_classes/object/any_of_spec.rb +6 -6
- data/spec/open_classes/object/boolean_spec.rb +6 -6
- data/spec/open_classes/object/grep_instance_method_spec.rb +15 -15
- data/spec/open_classes/object/grep_method_spec.rb +6 -6
- data/spec/open_classes/object/guard_spec.rb +8 -8
- data/spec/open_classes/object/method_nameable_spec.rb +4 -4
- data/spec/open_classes/object/my_methods_spec.rb +2 -2
- data/spec/open_classes/object/null_spec.rb +1 -1
- data/spec/open_classes/object/to_bool_spec.rb +7 -7
- data/spec/open_classes/string/ascii1_other2_size_spec.rb +5 -5
- data/spec/open_classes/string/ascii_unicode_html_table_spec.rb +1 -1
- data/spec/open_classes/string/ascii_unicode_table_spec.rb +1 -1
- data/spec/open_classes/string/comma_to_a_spec.rb +1 -1
- data/spec/open_classes/string/cygwinpath_to_winpath_spec.rb +3 -3
- data/spec/open_classes/string/escape_double_quote_spec.rb +3 -3
- data/spec/open_classes/string/escape_quote_spec.rb +3 -3
- data/spec/open_classes/string/gte_gte_spec.rb +3 -3
- data/spec/open_classes/string/hyphen_to_a_spec.rb +1 -1
- data/spec/open_classes/string/is_meta_variable_spec.rb +3 -3
- data/spec/open_classes/string/justify_char_spec.rb +6 -6
- data/spec/open_classes/string/justify_table_spec.rb +6 -6
- data/spec/open_classes/string/say_spec.rb +2 -2
- data/spec/open_classes/string/spacing_spec.rb +6 -6
- data/spec/open_classes/string/surround_spec.rb +1 -1
- data/spec/open_classes/string/table_to_array_spec.rb +1 -1
- data/spec/open_classes/string/to_hatena_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_markdown_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_space2_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_space4_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_tab_heading_spec.rb +5 -5
- data/spec/open_classes/string/unescape_double_quote_spec.rb +3 -3
- data/spec/open_classes/string/unescape_quote_spec.rb +3 -3
- data/spec/open_classes/string/uniq_size_spec.rb +4 -4
- data/spec/open_classes/string/uniq_spec.rb +4 -4
- data/spec/open_classes/string/winpath_to_cygwinpath_spec.rb +3 -3
- data/spec/open_classes/symbol/is_meta_variable_spec.rb +3 -3
- data/spec/simple_tournament_spec.rb +9 -9
- data/spec/templatable_spec.rb +2 -2
- data/spec/template_methodable_spec.rb +1 -1
- data/spec/test_toolbox/kernel_spec.rb +7 -7
- data/tbpgr_utils.gemspec +4 -4
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cddb4ef5b5a62664a18980ee65073eab67f3638a
|
4
|
+
data.tar.gz: 4e5b54f89673365b5ebf9862c58b41eefa040acf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0bc952ebcdad7879e7e32146975b9d23b9aa273af3da5133e10e074f23489caeac7cdfd06cb94658ba1e7737302cb50e9ab948124a2765a627c015eec4761a
|
7
|
+
data.tar.gz: a31deb04838dc9e976c831426c40e92e47263b17803617600c141ccd4d0ca40d8039b872978d710a5d0cf56b1bffa8a05f66149432d0f8ce3ecb9c98759aac80
|
data/Gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
gem
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
group :test do
|
8
|
-
gem 'coveralls', require: false
|
9
|
-
end
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
gem 'rspec', '~> 2.14.1'
|
5
|
+
gem 'activesupport', '~> 4.0.1'
|
6
|
+
gem 'simplecov', '~> 0.8.2'
|
7
|
+
group :test do
|
8
|
+
gem 'coveralls', require: false
|
9
|
+
end
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# TbpgrUtils
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/tbpgr_utils)
|
3
4
|
[](https://travis-ci.org/tbpgr/tbpgr_utils)
|
4
5
|
[](https://coveralls.io/r/tbpgr/tbpgr_utils)
|
5
6
|
[](https://codeclimate.com/github/tbpgr/tbpgr_utils)
|
@@ -27,8 +28,6 @@ Or install it yourself as:
|
|
27
28
|
|[TbpgrUtils Array#>>](#array) |return ArrayContext for each execute |
|
28
29
|
|[TbpgrUtils Array#average](#arrayaverage) |return average |
|
29
30
|
|[TbpgrUtils Array#exchange](#arrayexchange ) |exchange array's elements |
|
30
|
-
|[TbpgrUtils Array#kernel_send](#arraykernel_send) |alias of map {|v|send :some_kernel_method, v} |
|
31
|
-
|[TbpgrUtils Array#sum](#arraysum) |alias of Array#reduce(&:+). |
|
32
31
|
|[TbpgrUtils Array#to_table](#arrayto_table) |Array(Array, Array...) to table format. |
|
33
32
|
|[TbpgrUtils Array#to_html_table](#arrayto_html_table) |Array(Array, Array...) to html table format. |
|
34
33
|
|[TbpgrUtils Array#together](#arraytogether) |loop all arrays by block |
|
@@ -60,6 +59,9 @@ Or install it yourself as:
|
|
60
59
|
|[TbpgrUtils Array#together_slice](#arraytogether_sliceor-tslice) |together version of Array#slice. together_slice has alias :tslice |
|
61
60
|
|[TbpgrUtils Array#together_with_index](#arraytogether_with_index) |loop all arrays by block with index |
|
62
61
|
|[TbpgrUtils Array#uniq_size](#arrayuniq_size) |return uniq size |
|
62
|
+
|[TbpgrUtils Enumerable#if_else_map](#enumerableif_else_map) |alias of map {|v|v.condition ? a : b} |
|
63
|
+
|[TbpgrUtils Enumerable#kernel_send](#enumerablekernel_send) |alias of map {|v|send :some_kernel_method, v} |
|
64
|
+
|[TbpgrUtils Enumerable#sum](#enumerablesum) |alias of Enumerable#reduce(&:+). |
|
63
65
|
|[AttrEnumerable.at_attr](#attrenumerableat_attr) |define at_xxx. it returns Class attributes(collection)'s at result. |
|
64
66
|
|[AttrEnumerable.compact_attr](#attrenumerablecompact_attr) |define compact_xxx. it returns Class attributes(collection)'s that exclude nil elements. |
|
65
67
|
|[AttrEnumerable.concat_attr](#attrenumerableconcat_attr) |define concat_xxx. it returns Class attributes(collection) and argument array |
|
@@ -139,7 +141,7 @@ Or install it yourself as:
|
|
139
141
|
|[TbpgrUtils Module.alias_methods](#modulealias_methods) |create alias methods |
|
140
142
|
|[TbpgrUtils Numeric#dice_back](#numericdice_back) |return dice back number |
|
141
143
|
|[TbpgrUtils Numeric#dozen](#numericdozen) |get dozen number |
|
142
|
-
|[TbpgrUtils Numeric#
|
144
|
+
|[TbpgrUtils Numeric#ascii?](#numericascii) |get ascii number |
|
143
145
|
|[TbpgrUtils Numeric to_binary_html_table](#numeric-to_binary_html_table) |binary html table |
|
144
146
|
|[TbpgrUtils Numeric to_binary_table](#numeric-to_binary_table) |binary table |
|
145
147
|
|[TbpgrUtils Numeric to_digit_html_table](#numeric-to_digit_html_table) |digit html table |
|
@@ -170,7 +172,7 @@ Or install it yourself as:
|
|
170
172
|
|[TbpgrUtils String#escape_quote](#stringescape_quote) |escape quote |
|
171
173
|
|[TbpgrUtils String#escape_double_quote](#stringescape_double_quote) |escape double quote |
|
172
174
|
|[TbpgrUtils String#hyphen_to_a](#stringhyphen_to_a) |hyphen-format string to array |
|
173
|
-
|[TbpgrUtils String#
|
175
|
+
|[TbpgrUtils String#meta_variable?](#stringmeta_variable) |is meta variable. |
|
174
176
|
|[TbpgrUtils String#justify_char](#stringjustify_char) |justify pipe format char string |
|
175
177
|
|[TbpgrUtils String#justify_table](#stringjustify_table) |justify pipe format table string |
|
176
178
|
|[TbpgrUtils String#say](#stringsay) |say string |
|
@@ -187,7 +189,7 @@ Or install it yourself as:
|
|
187
189
|
|[TbpgrUtils String#uniq](#stringuniq) |return uniq string |
|
188
190
|
|[TbpgrUtils String#uniq_size](#stringuniq) |return uniq size |
|
189
191
|
|[TbpgrUtils String#winpath_to_cygwinpath](#stringwinpath_to_cygwinpath) |convert windows path to cygwin path |
|
190
|
-
|[TbpgrUtils Symbol#
|
192
|
+
|[TbpgrUtils Symbol#meta_variable?](#symbolmeta_variable) |is meta variable. |
|
191
193
|
|[Templatable module](#templatable) |get result from template + placeholder |
|
192
194
|
|[TemplateMethodable module](#templatemethodable) |for Template Method Pattern |
|
193
195
|
|
@@ -221,16 +223,6 @@ require 'tbpgr_utils'
|
|
221
223
|
|
222
224
|
[back to list](#list)
|
223
225
|
|
224
|
-
### Array#kernel_send
|
225
|
-
~~~ruby
|
226
|
-
require 'tbpgr_utils'
|
227
|
-
[*1..3].kernel_send:Rational # => [(1/1), (2/1), (3/1)]
|
228
|
-
[*1..3].kernel_send:print # => 123
|
229
|
-
[*65..68].kernel_send :putc # => ABCD
|
230
|
-
~~~
|
231
|
-
|
232
|
-
[back to list](#list)
|
233
|
-
|
234
226
|
### Array#to_table
|
235
227
|
~~~ruby
|
236
228
|
require 'tbpgr_utils'
|
@@ -2330,6 +2322,76 @@ output
|
|
2330
2322
|
|
2331
2323
|
[back to list](#list)
|
2332
2324
|
|
2325
|
+
### Enumerable#if_else_map
|
2326
|
+
~~~ruby
|
2327
|
+
require 'tbpgr_utils'
|
2328
|
+
[*1..4].if_else_map(
|
2329
|
+
:odd?.to_proc,
|
2330
|
+
->(odd){'odd'},
|
2331
|
+
->(even){'even'}
|
2332
|
+
)
|
2333
|
+
__END__
|
2334
|
+
["odd", "even", "odd", "even"]
|
2335
|
+
~~~
|
2336
|
+
|
2337
|
+
~~~ruby
|
2338
|
+
require 'tbpgr_utils'
|
2339
|
+
[*?a..?z].if_else_map(
|
2340
|
+
:vowel?.to_proc,
|
2341
|
+
->(alph){ "#{alph} is vowel" },
|
2342
|
+
->(alph){ "#{alph} is not vowel" }
|
2343
|
+
)
|
2344
|
+
|
2345
|
+
__END__
|
2346
|
+
["a is vowel",
|
2347
|
+
"b is not vowel",
|
2348
|
+
"c is not vowel",
|
2349
|
+
"d is not vowel",
|
2350
|
+
"e is vowel",
|
2351
|
+
"f is not vowel",
|
2352
|
+
"g is not vowel",
|
2353
|
+
"h is not vowel",
|
2354
|
+
"i is vowel",
|
2355
|
+
"j is not vowel",
|
2356
|
+
"k is not vowel",
|
2357
|
+
"l is not vowel",
|
2358
|
+
"m is not vowel",
|
2359
|
+
"n is not vowel",
|
2360
|
+
"o is vowel",
|
2361
|
+
"p is not vowel",
|
2362
|
+
"q is not vowel",
|
2363
|
+
"r is not vowel",
|
2364
|
+
"s is not vowel",
|
2365
|
+
"t is not vowel",
|
2366
|
+
"u is vowel",
|
2367
|
+
"v is not vowel",
|
2368
|
+
"w is not vowel",
|
2369
|
+
"x is not vowel",
|
2370
|
+
"y is not vowel",
|
2371
|
+
"z is not vowel"]
|
2372
|
+
~~~
|
2373
|
+
|
2374
|
+
[back to list](#list)
|
2375
|
+
|
2376
|
+
### Enumerable#kernel_send
|
2377
|
+
~~~ruby
|
2378
|
+
require 'tbpgr_utils'
|
2379
|
+
[*1..3].kernel_send:Rational # => [(1/1), (2/1), (3/1)]
|
2380
|
+
[*1..3].kernel_send:print # => 123
|
2381
|
+
[*65..68].kernel_send :putc # => ABCD
|
2382
|
+
~~~
|
2383
|
+
|
2384
|
+
[back to list](#list)
|
2385
|
+
|
2386
|
+
### Enumerable#sum
|
2387
|
+
~~~ruby
|
2388
|
+
require 'tbpgr_utils'
|
2389
|
+
[*1..5].sum # => 15
|
2390
|
+
[*?a..?e].sum # => "abcde"
|
2391
|
+
~~~
|
2392
|
+
|
2393
|
+
[back to list](#list)
|
2394
|
+
|
2333
2395
|
### EvalHelper Object
|
2334
2396
|
|
2335
2397
|
enable to use EvalHelper in Object
|
@@ -3254,15 +3316,15 @@ require 'tbpgr_utils'
|
|
3254
3316
|
|
3255
3317
|
[back to list](#list)
|
3256
3318
|
|
3257
|
-
### Numeric#
|
3319
|
+
### Numeric#ascii?
|
3258
3320
|
|
3259
3321
|
1,127,128 case
|
3260
3322
|
~~~ruby
|
3261
3323
|
require 'tbpgr_utils'
|
3262
3324
|
|
3263
|
-
1.
|
3264
|
-
127.
|
3265
|
-
128.
|
3325
|
+
1.ascii? # => return true
|
3326
|
+
127.ascii? # => return true
|
3327
|
+
128.ascii? # => return false
|
3266
3328
|
~~~
|
3267
3329
|
|
3268
3330
|
[back to list](#list)
|
@@ -3874,13 +3936,13 @@ require 'tbpgr_utils'
|
|
3874
3936
|
|
3875
3937
|
[back to list](#list)
|
3876
3938
|
|
3877
|
-
### String#
|
3939
|
+
### String#meta_variable?
|
3878
3940
|
~~~ruby
|
3879
|
-
'foo'.
|
3880
|
-
'bar'.
|
3881
|
-
'baz'.
|
3882
|
-
'aaa'.
|
3883
|
-
''.
|
3941
|
+
'foo'.meta_variable? # => true
|
3942
|
+
'bar'.meta_variable? # => true
|
3943
|
+
'baz'.meta_variable? # => true
|
3944
|
+
'aaa'.meta_variable? # => false
|
3945
|
+
''.meta_variable? # => false
|
3884
3946
|
~~~
|
3885
3947
|
|
3886
3948
|
[back to list](#list)
|
@@ -4219,12 +4281,12 @@ require 'tbpgr_utils'
|
|
4219
4281
|
|
4220
4282
|
[back to list](#list)
|
4221
4283
|
|
4222
|
-
### Symbol#
|
4284
|
+
### Symbol#meta_variable?
|
4223
4285
|
~~~ruby
|
4224
|
-
:foo.
|
4225
|
-
:bar.
|
4226
|
-
:baz.
|
4227
|
-
:aaa.
|
4286
|
+
:foo.meta_variable? # => true
|
4287
|
+
:bar.meta_variable? # => true
|
4288
|
+
:baz.meta_variable? # => true
|
4289
|
+
:aaa.meta_variable? # => false
|
4228
4290
|
~~~
|
4229
4291
|
|
4230
4292
|
[back to list](#list)
|
@@ -4329,6 +4391,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
4329
4391
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
4330
4392
|
|
4331
4393
|
## History
|
4394
|
+
* version 0.0.151 : add Enumerable#if_else_map, change class Array#sum to Enumerable#sum, change class Array#kernel_send to Enumerable#kernel_send
|
4332
4395
|
* version 0.0.150 : add AttrEnumerable.slice_attr
|
4333
4396
|
* version 0.0.149 : add AttrEnumerable.shuffle_attr
|
4334
4397
|
* version 0.0.148 : add AttrEnumerable.select_attr
|
@@ -4402,8 +4465,8 @@ https://github.com/tbpgr/tbpgr_utils_snippets
|
|
4402
4465
|
* version 0.0.80 : add Numeric to_binary_table
|
4403
4466
|
* version 0.0.79 : add Array#to_table
|
4404
4467
|
* version 0.0.78 : add String#ascii_unicode_table
|
4405
|
-
* version 0.0.77 : add String#
|
4406
|
-
* version 0.0.76 : add EvalHelper#attr_init_class_code, Numeric#
|
4468
|
+
* version 0.0.77 : add String#meta_variable?, Symbol#meta_variable?
|
4469
|
+
* version 0.0.76 : add EvalHelper#attr_init_class_code, Numeric#ascii?, String#ascii1_other2_size
|
4407
4470
|
* version 0.0.75 : add Object#method_nameable?
|
4408
4471
|
* version 0.0.74 : add Hash#table
|
4409
4472
|
* version 0.0.73 : add Kernel#evalb
|
@@ -1,52 +1,52 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'active_support/inflector'
|
3
|
-
|
4
|
-
# AttrEnumerable
|
5
|
-
module AttrEnumerable
|
6
|
-
ATTR_METHODS = [
|
7
|
-
{ regexp: /^each_(.*)_with_index$/, call_method: :each_attr_with_index },
|
8
|
-
{ regexp: /^each_(.*)$/, call_method: :each_attr },
|
9
|
-
{ regexp: /^reverse_(.*)$/, call_method: :reverse_attr },
|
10
|
-
{ regexp: /^at_(.*)$/, call_method: :at_attr },
|
11
|
-
{ regexp: /^compact_(.*)$/, call_method: :compact_attr },
|
12
|
-
{ regexp: /^concat_(.*)$/, call_method: :concat_attr },
|
13
|
-
{ regexp: /^delete_(.*)$/, call_method: :delete_attr },
|
14
|
-
{ regexp: /^first_(.*)$/, call_method: :first_attr },
|
15
|
-
{ regexp: /^include_(.*)\?$/, call_method: :include_attribute? },
|
16
|
-
{ regexp: /^last_(.*)$/, call_method: :last_attr },
|
17
|
-
{ regexp: /^map_(.*)$/, call_method: :map_attr },
|
18
|
-
{ regexp: /^reduce_(.*)$/, call_method: :reduce_attr },
|
19
|
-
{ regexp: /^sample_(.*)$/, call_method: :sample_attr },
|
20
|
-
{ regexp: /^select_(.*)$/, call_method: :select_attr },
|
21
|
-
{ regexp: /^shuffle_(.*)$/, call_method: :shuffle_attr },
|
22
|
-
{ regexp: /^slice_(.*)$/, call_method: :slice_attr }
|
23
|
-
]
|
24
|
-
|
25
|
-
# call attr enumerable method.
|
26
|
-
def method_missing(method_name, *args, &block)
|
27
|
-
target_method = detect(method_name)
|
28
|
-
send(target_method[:call_method], target_method[:attribute], method_name, *args, &block)
|
29
|
-
rescue
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
def detect(method_name)
|
35
|
-
ATTR_METHODS.each do |target_method|
|
36
|
-
regexp = target_method[:regexp]
|
37
|
-
if method_name.to_s =~ regexp
|
38
|
-
attribute = method_name.to_s.scan(regexp).first.first
|
39
|
-
return { call_method: target_method[:call_method], attribute: attribute }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
fail NoMethodError, "method is not exists #{method_name}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def include_attr?(element, attribute)
|
46
|
-
element.instance_variables.include? :"@#{attribute}"
|
47
|
-
end
|
48
|
-
|
49
|
-
def collection
|
50
|
-
instance_variable_get("@#{self.class.name.underscore}")
|
51
|
-
end
|
52
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'active_support/inflector'
|
3
|
+
|
4
|
+
# AttrEnumerable
|
5
|
+
module AttrEnumerable
|
6
|
+
ATTR_METHODS = [
|
7
|
+
{ regexp: /^each_(.*)_with_index$/, call_method: :each_attr_with_index },
|
8
|
+
{ regexp: /^each_(.*)$/, call_method: :each_attr },
|
9
|
+
{ regexp: /^reverse_(.*)$/, call_method: :reverse_attr },
|
10
|
+
{ regexp: /^at_(.*)$/, call_method: :at_attr },
|
11
|
+
{ regexp: /^compact_(.*)$/, call_method: :compact_attr },
|
12
|
+
{ regexp: /^concat_(.*)$/, call_method: :concat_attr },
|
13
|
+
{ regexp: /^delete_(.*)$/, call_method: :delete_attr },
|
14
|
+
{ regexp: /^first_(.*)$/, call_method: :first_attr },
|
15
|
+
{ regexp: /^include_(.*)\?$/, call_method: :include_attribute? },
|
16
|
+
{ regexp: /^last_(.*)$/, call_method: :last_attr },
|
17
|
+
{ regexp: /^map_(.*)$/, call_method: :map_attr },
|
18
|
+
{ regexp: /^reduce_(.*)$/, call_method: :reduce_attr },
|
19
|
+
{ regexp: /^sample_(.*)$/, call_method: :sample_attr },
|
20
|
+
{ regexp: /^select_(.*)$/, call_method: :select_attr },
|
21
|
+
{ regexp: /^shuffle_(.*)$/, call_method: :shuffle_attr },
|
22
|
+
{ regexp: /^slice_(.*)$/, call_method: :slice_attr }
|
23
|
+
]
|
24
|
+
|
25
|
+
# call attr enumerable method.
|
26
|
+
def method_missing(method_name, *args, &block)
|
27
|
+
target_method = detect(method_name)
|
28
|
+
send(target_method[:call_method], target_method[:attribute], method_name, *args, &block)
|
29
|
+
rescue
|
30
|
+
raise
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def detect(method_name)
|
35
|
+
ATTR_METHODS.each do |target_method|
|
36
|
+
regexp = target_method[:regexp]
|
37
|
+
if method_name.to_s =~ regexp
|
38
|
+
attribute = method_name.to_s.scan(regexp).first.first
|
39
|
+
return { call_method: target_method[:call_method], attribute: attribute }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
fail NoMethodError, "method is not exists #{method_name}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def include_attr?(element, attribute)
|
46
|
+
element.instance_variables.include? :"@#{attribute}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def collection
|
50
|
+
instance_variable_get("@#{self.class.name.underscore}")
|
51
|
+
end
|
52
|
+
end
|
@@ -9,6 +9,6 @@ module AttrEnumerable
|
|
9
9
|
return [] if col.empty?
|
10
10
|
fail ArgumentError, "invalid attribute #{attribute}" unless include_attr?(col.first, attribute)
|
11
11
|
attrs = col.map { |v|v.send(attribute) }
|
12
|
-
attrs.reduce([]) { |
|
12
|
+
attrs.reduce([]) { |a, e|a << yield(e); a }
|
13
13
|
end
|
14
14
|
end
|
@@ -55,9 +55,9 @@ module EvalHelper
|
|
55
55
|
atrs = attribute
|
56
56
|
end
|
57
57
|
|
58
|
-
accessors = atrs.reduce([]) { |
|
59
|
-
init_variables = atrs.reduce([]) { |
|
60
|
-
set_variables = atrs.reduce([]) { |
|
58
|
+
accessors = atrs.reduce([]) { |a, e|a << ":#{e}" }.join(', ')
|
59
|
+
init_variables = atrs.reduce([]) { |a, e|a << "#{e}" }.join(', ')
|
60
|
+
set_variables = atrs.reduce([]) { |a, e|a << " @#{e} = #{e}" }.join("\n")
|
61
61
|
ret_code = <<-EOS
|
62
62
|
attr_accessor #{accessors}
|
63
63
|
|
@@ -1,26 +1,26 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module EvalHelper
|
4
|
-
# create each do code, for eval
|
5
|
-
#
|
6
|
-
# ==== Examples
|
7
|
-
#
|
8
|
-
# class EvalHelperEacjBraceTest
|
9
|
-
# include EvalHelper
|
10
|
-
#
|
11
|
-
# def hoge(hash)
|
12
|
-
# each_do_code(hash[:target], hash[:proc])
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# hash = {
|
17
|
-
# target: '[:a, :b]',
|
18
|
-
# proc: "puts \"\#{v}1\"\nputs \"\#{v}2\"\n",
|
19
|
-
# }
|
20
|
-
# EvalHelperEacjBraceTest.new.hoge(hash) # => return "[:a, :b].each do |v|\n puts \"\#{v}1\"\n puts \"\#{v}2\"\nend"
|
21
|
-
#
|
22
|
-
def each_do_code(target, proc)
|
23
|
-
indented = proc.split("\n").reduce([]) { |
|
24
|
-
"#{target}.each do |v|\n#{indented}\nend"
|
25
|
-
end
|
26
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EvalHelper
|
4
|
+
# create each do code, for eval
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# class EvalHelperEacjBraceTest
|
9
|
+
# include EvalHelper
|
10
|
+
#
|
11
|
+
# def hoge(hash)
|
12
|
+
# each_do_code(hash[:target], hash[:proc])
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# hash = {
|
17
|
+
# target: '[:a, :b]',
|
18
|
+
# proc: "puts \"\#{v}1\"\nputs \"\#{v}2\"\n",
|
19
|
+
# }
|
20
|
+
# EvalHelperEacjBraceTest.new.hoge(hash) # => return "[:a, :b].each do |v|\n puts \"\#{v}1\"\n puts \"\#{v}2\"\nend"
|
21
|
+
#
|
22
|
+
def each_do_code(target, proc)
|
23
|
+
indented = proc.split("\n").reduce([]) { |a, e|a << " #{e}"; a }.join("\n")
|
24
|
+
"#{target}.each do |v|\n#{indented}\nend"
|
25
|
+
end
|
26
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module EvalHelper
|
4
|
-
# create each with index do single line code, for eval
|
5
|
-
#
|
6
|
-
# ==== Examples
|
7
|
-
#
|
8
|
-
# class EvalHelperEachWithIndexDoTest
|
9
|
-
# include EvalHelper
|
10
|
-
#
|
11
|
-
# def hoge(hash)
|
12
|
-
# each_with_index_do_code(hash[:target], hash[:proc])
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# hash = {
|
17
|
-
# target: '[:a, :b]',
|
18
|
-
# proc: "puts \"\#{i}:\#{v}1\"\nputs \"\#{i}:\#{v}2\"\n",
|
19
|
-
# }
|
20
|
-
# EvalHelperEachWithIndexDoTest.new.hoge(hash) # => return "[:a, :b].each_with_index do |v, i|\n puts \"\#{i}:\#{v}1\"\n puts \"\#{i}:\#{v}2\"\nend"
|
21
|
-
#
|
22
|
-
def each_with_index_do_code(target, proc)
|
23
|
-
indented = proc.split("\n").reduce([]) { |
|
24
|
-
"#{target}.each_with_index do |v, i|\n#{indented}\nend"
|
25
|
-
end
|
26
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EvalHelper
|
4
|
+
# create each with index do single line code, for eval
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# class EvalHelperEachWithIndexDoTest
|
9
|
+
# include EvalHelper
|
10
|
+
#
|
11
|
+
# def hoge(hash)
|
12
|
+
# each_with_index_do_code(hash[:target], hash[:proc])
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# hash = {
|
17
|
+
# target: '[:a, :b]',
|
18
|
+
# proc: "puts \"\#{i}:\#{v}1\"\nputs \"\#{i}:\#{v}2\"\n",
|
19
|
+
# }
|
20
|
+
# EvalHelperEachWithIndexDoTest.new.hoge(hash) # => return "[:a, :b].each_with_index do |v, i|\n puts \"\#{i}:\#{v}1\"\n puts \"\#{i}:\#{v}2\"\nend"
|
21
|
+
#
|
22
|
+
def each_with_index_do_code(target, proc)
|
23
|
+
indented = proc.split("\n").reduce([]) { |a, e|a << " #{e}"; a }.join("\n")
|
24
|
+
"#{target}.each_with_index do |v, i|\n#{indented}\nend"
|
25
|
+
end
|
26
|
+
end
|