facets 2.9.3 → 3.0.0
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 +7 -0
- data/.index +76 -0
- data/CONTRIBUTE.md +78 -0
- data/HISTORY.md +2459 -0
- data/{RUBY.txt → LICENSE.txt} +0 -0
- data/README.rdoc +29 -7
- data/demo/applique/assertion_framework.rb +1 -0
- data/{qed → demo}/applique/file_helpers.rb +0 -0
- data/{qed → demo}/core/array/combination.rdoc +0 -0
- data/{qed → demo}/core/array/delete.rdoc +0 -0
- data/{qed → demo}/core/array/index.rdoc +0 -0
- data/{qed → demo}/core/array/merge.rdoc +0 -0
- data/{qed → demo}/core/array/only.rdoc +0 -0
- data/{qed → demo}/core/array/pad.rdoc +0 -0
- data/{qed → demo}/core/array/permutation.rdoc +0 -0
- data/{qed → demo}/core/array/product.rdoc +0 -0
- data/{qed → demo}/core/array/recursively.rdoc +0 -0
- data/{qed → demo}/core/array/rotate.rdoc +0 -0
- data/{qed → demo}/core/array/select.rdoc +0 -0
- data/{qed → demo}/core/array/uniq_by.rdoc +0 -0
- data/{qed → demo}/core/binding/caller.rdoc +0 -0
- data/{qed → demo}/core/binding/defined.rdoc +0 -0
- data/{qed → demo}/core/binding/eval.rdoc +0 -0
- data/{qed → demo}/core/binding/local_variables.rdoc +0 -0
- data/{qed → demo}/core/binding/opvars.rdoc +0 -0
- data/{qed → demo}/core/binding/self.rdoc +0 -0
- data/{qed → demo}/core/class/descendants.rdoc +0 -0
- data/{qed → demo}/core/class/to_proc.rdoc +0 -0
- data/{qed → demo}/core/comparable/cap.rdoc +0 -0
- data/{qed → demo}/core/comparable/clip.rdoc +0 -0
- data/{qed → demo}/core/comparable/cmp.rdoc +0 -0
- data/{qed → demo}/core/comparable/op_get.rdoc +0 -0
- data/{qed → demo}/core/dir/ascend.rdoc +0 -0
- data/{qed → demo}/core/dir/descend.rdoc +0 -0
- data/{qed → demo}/core/dir/multiglob.rdoc +0 -0
- data/{qed → demo}/core/dir/parent.rdoc +0 -0
- data/{qed → demo}/core/dir/recurse.rdoc +0 -0
- data/{qed → demo}/core/exception/detail.rdoc +0 -0
- data/{qed → demo}/core/facets.rdoc +0 -0
- data/{qed → demo}/core/filetest/root.rdoc +0 -0
- data/{qed → demo}/core/hash/recursively.rdoc +0 -0
- data/{qed → demo}/core/indexable.rdoc +0 -0
- data/{qed → demo}/core/integer/bitmask.rdoc +0 -0
- data/{qed → demo}/core/integer/even.rdoc +0 -0
- data/{qed → demo}/core/integer/factorial.rdoc +0 -0
- data/{qed → demo}/core/integer/length.rdoc +0 -0
- data/{qed → demo}/core/integer/multiple.rdoc +0 -0
- data/{qed → demo}/core/integer/odd.rdoc +0 -0
- data/{qed → demo}/core/integer/of.rdoc +0 -0
- data/{qed → demo}/core/integer/ordinal.rdoc +0 -0
- data/{qed → demo}/core/matchdata/match.rdoc +0 -0
- data/{qed → demo}/core/matchdata/matchset.rdoc +0 -0
- data/{qed → demo}/core/module/cattr.rdoc +0 -0
- data/{qed → demo}/core/module/class_extend.rdoc +0 -0
- data/{qed → demo}/core/module/class_inheritor.rdoc +0 -0
- data/{qed → demo}/core/module/copy_inheritor.rdoc +0 -0
- data/{qed → demo}/core/module/method_space.rdoc +0 -0
- data/{qed → demo}/core/string/align.rdoc +0 -0
- data/{qed → demo}/core/string/bracket.rdoc +0 -0
- data/{qed → demo}/core/string/bytes.rdoc +0 -0
- data/{qed → demo}/core/string/camelcase.rdoc +0 -0
- data/{qed → demo}/core/string/capitalized.rdoc +0 -0
- data/{qed → demo}/core/string/characters.rdoc +0 -0
- data/{qed → demo}/core/string/cleanlines.rdoc +0 -0
- data/{qed → demo}/core/string/cleave.rdoc +0 -0
- data/{qed → demo}/core/string/divide.rdoc +0 -0
- data/{qed → demo}/core/string/each_char.rdoc +0 -0
- data/{qed → demo}/core/string/each_word.rdoc +0 -0
- data/{qed → demo}/core/string/end_with.rdoc +0 -0
- data/{qed → demo}/core/string/expand_tabs.rdoc +0 -0
- data/{qed → demo}/core/string/fold.rdoc +0 -0
- data/{qed → demo}/core/string/indent.rdoc +0 -0
- data/{qed → demo}/core/string/interpolate.rdoc +0 -0
- data/{qed → demo}/core/string/lchomp.rdoc +0 -0
- data/{qed → demo}/core/string/line_wrap.rdoc +0 -0
- data/{qed → demo}/core/string/lines.rdoc +0 -0
- data/{qed → demo}/core/string/margin.rdoc +0 -0
- data/{qed → demo}/core/string/methodize.rdoc +0 -0
- data/{qed → demo}/core/string/modulize.rdoc +0 -0
- data/{qed → demo}/core/string/mscan.rdoc +0 -0
- data/{qed → demo}/core/string/natcmp.rdoc +0 -0
- data/{qed → demo}/core/string/nchar.rdoc +0 -0
- data/{qed → demo}/core/string/newlines.rdoc +0 -0
- data/{qed → demo}/core/string/op_sub.rdoc +0 -0
- data/{qed → demo}/core/string/pathize.rdoc +0 -0
- data/{qed → demo}/core/string/quote.rdoc +0 -0
- data/{qed → demo}/core/string/range.rdoc +0 -0
- data/{qed → demo}/core/string/rewrite.rdoc +0 -0
- data/{qed → demo}/core/string/shatter.rdoc +0 -0
- data/{qed → demo}/core/string/snakecase.rdoc +0 -0
- data/{qed → demo}/core/string/splice.rdoc +0 -0
- data/{qed → demo}/core/string/start_with.rdoc +0 -0
- data/{qed → demo}/core/string/subtract.rdoc +0 -0
- data/{qed → demo}/core/string/tab.rdoc +0 -0
- data/{qed → demo}/core/string/tabto.rdoc +0 -0
- data/{qed → demo}/core/string/titlecase.rdoc +0 -0
- data/{qed → demo}/core/string/to_re.rdoc +0 -0
- data/{qed → demo}/core/string/unfold.rdoc +0 -0
- data/{qed → demo}/core/string/unindent.rdoc +0 -0
- data/{qed → demo}/core/string/unquote.rdoc +0 -0
- data/{qed → demo}/core/string/variablize.rdoc +0 -0
- data/{qed → demo}/core/string/word_wrap.rdoc +0 -0
- data/{qed → demo}/core/string/words.rdoc +0 -0
- data/{qed → demo}/core/string/xor.rdoc +0 -0
- data/{qed → demo}/standard/02_cloneable.rdoc +0 -0
- data/{qed → demo}/standard/03_enumargs.rdoc +0 -0
- data/{qed → demo}/standard/04_equitable.rdoc +0 -0
- data/{qed → demo}/standard/05_instantiable.rdoc +0 -0
- data/{qed → demo}/standard/basic_object.rdoc +0 -0
- data/{qed → demo}/standard/memoizable.rdoc +0 -0
- data/{qed → demo}/standard/mulititon.rdoc +0 -0
- data/lib/core/facets.rb +1 -2
- data/lib/core/facets.yml +61 -42
- data/lib/core/facets/array.rb +8 -28
- data/lib/core/facets/array/arrange.rb +42 -0
- data/lib/core/facets/array/before.rb +2 -0
- data/lib/core/facets/array/collapse.rb +2 -0
- data/lib/core/facets/array/commonality.rb +24 -12
- data/lib/core/facets/array/duplicates.rb +22 -1
- data/lib/core/facets/array/each_overlap.rb +25 -0
- data/lib/core/facets/array/intersection.rb +25 -0
- data/lib/core/facets/array/missing.rb +29 -0
- data/lib/core/facets/array/nonuniq.rb +7 -53
- data/lib/core/facets/array/occur.rb +38 -0
- data/lib/core/facets/array/occurrence.rb +28 -0
- data/lib/core/facets/array/only.rb +12 -1
- data/lib/core/facets/array/recursively.rb +11 -5
- data/lib/core/facets/array/reject_values.rb +21 -0
- data/lib/core/facets/array/splice.rb +5 -1
- data/lib/core/facets/array/split.rb +5 -2
- data/lib/core/facets/array/squeeze.rb +23 -0
- data/lib/core/facets/array/step.rb +31 -0
- data/lib/core/facets/array/store.rb +4 -0
- data/lib/core/facets/array/to_h.rb +22 -0
- data/lib/core/facets/array/traverse.rb +11 -5
- data/lib/core/facets/array/uniq_by.rb +5 -1
- data/lib/core/facets/array/unique_permutation.rb +29 -0
- data/lib/core/facets/array/zip.rb +21 -0
- data/lib/core/facets/binding.rb +0 -3
- data/lib/core/facets/binding/call_stack.rb +1 -1
- data/lib/core/facets/binding/caller.rb +1 -3
- data/lib/core/facets/binding/callstack.rb +1 -1
- data/lib/core/facets/binding/defined.rb +0 -2
- data/lib/core/facets/binding/local_variables.rb +0 -2
- data/lib/core/facets/binding/op_get.rb +0 -2
- data/lib/core/facets/binding/self.rb +1 -3
- data/lib/core/facets/cattr.rb +1 -0
- data/lib/core/facets/class.rb +0 -2
- data/lib/core/facets/class/cattr.rb +1 -0
- data/lib/core/facets/class/singleton.rb +1 -13
- data/lib/core/facets/class/singleton_class.rb +16 -0
- data/lib/core/facets/comparable.rb +0 -2
- data/lib/core/facets/dir.rb +0 -2
- data/lib/core/facets/dir/ascend.rb +2 -2
- data/lib/core/facets/dir/lookup.rb +20 -0
- data/lib/core/facets/enumerable.rb +10 -9
- data/lib/core/facets/enumerable/accumulate.rb +18 -16
- data/lib/core/facets/enumerable/apply.rb +20 -0
- data/lib/core/facets/enumerable/associate.rb +6 -0
- data/lib/core/facets/enumerable/cluster.rb +24 -0
- data/lib/core/facets/enumerable/every.rb +1 -1
- data/lib/core/facets/enumerable/ewise.rb +2 -0
- data/lib/core/facets/enumerable/graph.rb +0 -3
- data/lib/core/facets/enumerable/hashify.rb +222 -19
- data/lib/core/facets/enumerable/hinge.rb +18 -0
- data/lib/core/facets/enumerable/key_by.rb +27 -0
- data/lib/core/facets/enumerable/map_to.rb +13 -0
- data/lib/core/facets/enumerable/mash.rb +34 -1
- data/lib/core/facets/enumerable/occur.rb +12 -9
- data/lib/core/facets/enumerable/only.rb +56 -0
- data/lib/core/facets/enumerable/{cluster_by.rb → organize_by.rb} +5 -4
- data/lib/core/facets/enumerable/pair.rb +20 -0
- data/lib/core/facets/enumerable/per.rb +27 -35
- data/lib/core/facets/enumerable/recursively.rb +3 -3
- data/lib/core/facets/enumerable/squeeze.rb +36 -0
- data/lib/core/facets/enumerable/sum.rb +18 -6
- data/lib/core/facets/enumerable/unassociate.rb +23 -0
- data/lib/core/facets/enumerable/value_by.rb +25 -0
- data/lib/core/facets/enumerator/fx.rb +16 -25
- data/lib/core/facets/enumerator/lazy/squeeze.rb +33 -0
- data/lib/core/facets/essentials.rb +65 -0
- data/lib/core/facets/exception.rb +0 -2
- data/lib/core/facets/exception/set_message.rb +10 -0
- data/lib/core/facets/file.rb +1 -2
- data/lib/core/facets/file/common_path.rb +17 -0
- data/lib/core/facets/file/rootname.rb +1 -1
- data/lib/core/facets/filetest.rb +0 -2
- data/lib/core/facets/filetest/relative.rb +1 -1
- data/lib/core/facets/filetest/safe.rb +14 -10
- data/lib/core/facets/float.rb +1 -3
- data/lib/core/facets/float/round_to.rb +1 -0
- data/lib/core/facets/functor.rb +8 -10
- data/lib/core/facets/hash.rb +2 -5
- data/lib/core/facets/hash/collate.rb +22 -8
- data/lib/core/facets/hash/count.rb +8 -4
- data/lib/core/facets/hash/data.rb +5 -2
- data/lib/core/facets/hash/dearray_values.rb +1 -1
- data/lib/core/facets/hash/deep_rekey.rb +54 -0
- data/lib/core/facets/hash/each_with_key.rb +12 -0
- data/lib/core/facets/hash/fetch_nested.rb +20 -0
- data/lib/core/facets/hash/keys.rb +4 -13
- data/lib/core/facets/hash/only_keys.rb +1 -0
- data/lib/core/facets/hash/op_push.rb +9 -1
- data/lib/core/facets/hash/op_sub.rb +1 -1
- data/lib/core/facets/hash/recursively.rb +6 -6
- data/lib/core/facets/hash/rekey.rb +26 -34
- data/lib/core/facets/hash/revalue.rb +61 -0
- data/lib/core/facets/hash/slice.rb +16 -3
- data/lib/core/facets/hash/subset.rb +11 -8
- data/lib/core/facets/hash/update_each.rb +1 -1
- data/lib/core/facets/hash/weave.rb +1 -1
- data/lib/core/facets/indexable.rb +6 -6
- data/lib/core/facets/integer.rb +0 -4
- data/lib/core/facets/kernel.rb +4 -7
- data/lib/core/facets/kernel/__dir__.rb +2 -0
- data/lib/core/facets/kernel/as.rb +2 -1
- data/lib/core/facets/kernel/call_stack.rb +1 -56
- data/lib/core/facets/kernel/callstack.rb +56 -1
- data/lib/core/facets/kernel/constant.rb +2 -0
- data/lib/core/facets/kernel/deep_clone.rb +27 -1
- data/lib/core/facets/kernel/deep_copy.rb +0 -24
- data/lib/core/facets/kernel/eigen.rb +2 -33
- data/lib/core/facets/kernel/eigenclass.rb +1 -1
- data/lib/core/facets/kernel/ergo.rb +1 -1
- data/lib/core/facets/kernel/extend.rb +4 -6
- data/lib/core/facets/kernel/instance_assign.rb +8 -6
- data/lib/core/facets/kernel/instance_extract.rb +22 -0
- data/lib/core/facets/kernel/instance_replace.rb +40 -0
- data/lib/core/facets/kernel/{equate.rb → like.rb} +7 -4
- data/lib/core/facets/kernel/load_relative.rb +25 -1
- data/lib/core/facets/kernel/meta.rb +35 -0
- data/lib/core/facets/kernel/meta_def.rb +4 -0
- data/lib/core/facets/kernel/object_send.rb +11 -14
- data/lib/core/facets/kernel/respond.rb +3 -13
- data/lib/core/facets/kernel/tap.rb +27 -39
- data/lib/core/facets/load_path.rb +1 -0
- data/lib/core/facets/load_path/search.rb +16 -0
- data/lib/core/facets/matchdata.rb +0 -2
- data/lib/core/facets/method.rb +0 -2
- data/lib/core/facets/method/composition.rb +32 -16
- data/lib/core/facets/method/curry.rb +13 -0
- data/lib/core/facets/method/partial.rb +10 -0
- data/lib/core/facets/method/public.rb +33 -0
- data/lib/core/facets/module.rb +0 -2
- data/lib/core/facets/module/alias_class_method.rb +11 -0
- data/lib/core/facets/module/basename.rb +1 -31
- data/lib/core/facets/module/cattr.rb +1 -0
- data/lib/core/facets/module/lastname.rb +30 -0
- data/lib/core/facets/module/mattr.rb +4 -4
- data/lib/core/facets/nilclass.rb +0 -3
- data/lib/core/facets/numeric.rb +0 -4
- data/lib/core/facets/numeric/approx.rb +3 -2
- data/lib/core/facets/numeric/range.rb +12 -0
- data/lib/core/facets/numeric/round_to.rb +32 -1
- data/lib/core/facets/object.rb +2 -3
- data/lib/core/facets/object/itself.rb +16 -0
- data/lib/core/facets/objectspace.rb +0 -3
- data/lib/core/facets/proc.rb +0 -3
- data/lib/core/facets/proc/bind_to.rb +3 -3
- data/lib/core/facets/proc/wrap.rb +17 -0
- data/lib/core/facets/process.rb +0 -2
- data/lib/core/facets/range.rb +4 -4
- data/lib/core/facets/range/op_add.rb +15 -0
- data/lib/core/facets/range/op_sub.rb +45 -0
- data/lib/core/facets/range/{to_r.rb → to_rng.rb} +1 -1
- data/lib/core/facets/regexp.rb +0 -2
- data/lib/core/facets/regexp/to_proc.rb +13 -0
- data/lib/core/facets/string.rb +8 -9
- data/lib/core/facets/string/ascii_only.rb +52 -0
- data/lib/core/facets/string/each_match.rb +1 -0
- data/lib/core/facets/string/ends_with.rb +1 -0
- data/lib/core/facets/string/file.rb +6 -20
- data/lib/core/facets/string/fold.rb +5 -5
- data/lib/core/facets/string/indent.rb +37 -20
- data/lib/core/facets/string/indexable.rb +7 -0
- data/lib/core/facets/string/interpolate.rb +6 -2
- data/lib/core/facets/string/linear.rb +19 -0
- data/lib/core/facets/string/margin.rb +47 -19
- data/lib/core/facets/string/mscan.rb +3 -0
- data/lib/core/facets/string/number.rb +14 -0
- data/lib/core/facets/string/op_sub.rb +1 -14
- data/lib/core/facets/string/random.rb +34 -0
- data/lib/core/facets/string/remove.rb +30 -0
- data/lib/core/facets/string/rotate.rb +24 -0
- data/lib/core/facets/string/similarity.rb +2 -2
- data/lib/core/facets/string/starts_with.rb +5 -0
- data/lib/core/facets/string/tab.rb +2 -17
- data/lib/core/facets/string/tabto.rb +2 -19
- data/lib/core/facets/string/to_rx.rb +1 -0
- data/lib/core/facets/string/trim.rb +45 -0
- data/lib/core/facets/string/unfold.rb +7 -2
- data/lib/core/facets/struct.rb +1 -2
- data/lib/core/facets/struct/replace.rb +8 -0
- data/lib/core/facets/symbol.rb +1 -3
- data/lib/core/facets/symbol/as_s.rb +3 -1
- data/lib/core/facets/symbol/call.rb +29 -0
- data/lib/core/facets/symbol/thrown.rb +9 -5
- data/lib/core/facets/time.rb +0 -2
- data/lib/core/facets/time/future.rb +6 -4
- data/lib/core/facets/unboundmethod.rb +0 -3
- data/lib/core/facets/version.rb +5 -5
- data/lib/standard/facets/against.rb +53 -0
- data/lib/standard/facets/binding/block_exec.rb +44 -0
- data/lib/standard/facets/cgi.rb +2 -40
- data/lib/standard/facets/cgi/esc.rb +11 -0
- data/lib/standard/facets/cgi/escape_html.rb +63 -0
- data/lib/standard/facets/cgi/marshal.rb +20 -0
- data/lib/standard/facets/cli.rb +54 -0
- data/lib/standard/facets/cloneable.rb +12 -9
- data/lib/standard/facets/enumargs.rb +159 -168
- data/lib/standard/facets/find.rb +1 -15
- data/lib/standard/facets/find/select.rb +16 -0
- data/lib/standard/facets/gem/search.rb +18 -0
- data/lib/standard/facets/gem/specification/current_specs.rb +21 -0
- data/lib/standard/facets/gem/specification/find_requireable_file.rb +21 -0
- data/lib/standard/facets/hash_builder.rb +46 -0
- data/lib/standard/facets/load_monitor.rb +26 -0
- data/lib/standard/facets/math.rb +57 -57
- data/lib/standard/facets/math/acosec.rb +1 -0
- data/lib/standard/facets/math/acsc.rb +6 -1
- data/lib/standard/facets/math/beta.rb +8 -3
- data/lib/standard/facets/math/cosec.rb +1 -0
- data/lib/standard/facets/math/cosech.rb +1 -0
- data/lib/standard/facets/math/csc.rb +6 -1
- data/lib/standard/facets/math/csch.rb +6 -1
- data/lib/standard/facets/math/distance.rb +19 -0
- data/lib/standard/facets/math/ec.rb +5 -0
- data/lib/standard/facets/math/lgamma.rb +21 -21
- data/lib/standard/facets/math/lngamma.rb +18 -0
- data/lib/standard/facets/math/pow.rb +6 -1
- data/lib/standard/facets/math/root.rb +1 -1
- data/lib/standard/facets/math/sign.rb +15 -4
- data/lib/standard/facets/math/tau.rb +5 -0
- data/lib/standard/facets/math/tgamma.rb +1 -1
- data/lib/standard/facets/memoizer.rb +63 -0
- data/lib/standard/facets/ostruct.rb +37 -156
- data/lib/standard/facets/ostruct/each.rb +11 -0
- data/lib/standard/facets/ostruct/initialize.rb +48 -0
- data/lib/standard/facets/ostruct/merge.rb +21 -0
- data/lib/standard/facets/ostruct/op_fetch.rb +29 -0
- data/lib/standard/facets/ostruct/op_store.rb +1 -0
- data/lib/standard/facets/ostruct/to_h.rb +10 -0
- data/lib/standard/facets/ostruct/to_ostruct.rb +65 -0
- data/lib/standard/facets/pathname.rb +18 -215
- data/lib/standard/facets/pathname/chdir.rb +15 -0
- data/lib/standard/facets/pathname/empty.rb +10 -0
- data/lib/standard/facets/pathname/exists.rb +6 -0
- data/lib/standard/facets/pathname/glob.rb +57 -0
- data/lib/standard/facets/pathname/home.rb +12 -0
- data/lib/standard/facets/pathname/null.rb +20 -0
- data/lib/standard/facets/pathname/op_div.rb +15 -0
- data/lib/standard/facets/pathname/op_fetch.rb +13 -0
- data/lib/standard/facets/pathname/outofdate.rb +13 -0
- data/lib/standard/facets/pathname/readline.rb +13 -0
- data/lib/standard/facets/pathname/root.rb +10 -0
- data/lib/standard/facets/pathname/rootname.rb +10 -0
- data/lib/standard/facets/pathname/safe.rb +15 -0
- data/lib/standard/facets/pathname/split_root.rb +9 -0
- data/lib/standard/facets/pathname/to_path.rb +28 -0
- data/lib/standard/facets/pathname/to_str.rb +8 -0
- data/lib/standard/facets/pathname/uptodate.rb +11 -0
- data/lib/standard/facets/pathname/visit.rb +38 -0
- data/lib/standard/facets/pathname/work.rb +10 -0
- data/lib/standard/facets/platform.rb +2 -2
- data/lib/standard/facets/random.rb +32 -2
- data/lib/standard/facets/shellwords.rb +5 -2
- data/lib/standard/facets/thread.rb +2 -2
- data/lib/standard/facets/uri.rb +7 -178
- data/lib/standard/facets/uri/cgi_escape.rb +46 -0
- data/lib/standard/facets/uri/cgi_parse.rb +1 -0
- data/lib/standard/facets/uri/cgi_unescape.rb +1 -0
- data/lib/standard/facets/uri/decode.rb +32 -0
- data/lib/standard/facets/uri/parameters.rb +63 -0
- data/lib/standard/facets/uri/query.rb +148 -0
- data/lib/standard/facets/yaml.rb +3 -56
- data/lib/standard/facets/yaml/file.rb +41 -0
- data/lib/standard/facets/yaml/kernel.rb +29 -0
- data/lib/standard/facets/yaml/read.rb +12 -0
- data/test/core/array/test_arrange.rb +37 -0
- data/test/core/array/test_each_overlap.rb +31 -0
- data/test/core/array/test_intersection.rb +19 -0
- data/test/core/array/test_missing.rb +12 -0
- data/test/core/array/test_occur.rb +52 -0
- data/test/core/array/test_occurrence.rb +20 -0
- data/test/core/array/test_reject_values.rb +17 -0
- data/test/core/array/test_squeeze.rb +22 -0
- data/test/core/array/test_step.rb +28 -0
- data/test/core/array/test_unique_permutation.rb +23 -0
- data/test/core/enumerable/test_key_by.rb +22 -0
- data/test/core/enumerable/test_occur.rb +18 -5
- data/test/core/enumerable/test_only.rb +40 -0
- data/test/core/enumerable/test_squeeze.rb +35 -0
- data/test/core/enumerable/test_sum.rb +8 -3
- data/test/core/enumerator/lazy/test_squeeze.rb +33 -0
- data/test/core/hash/test_count.rb +10 -1
- data/test/core/hash/test_deep_rekey.rb +131 -0
- data/test/core/hash/test_each_with_key.rb +16 -0
- data/test/core/hash/test_fetch_nested.rb +24 -0
- data/test/core/hash/test_keys.rb +0 -11
- data/test/core/hash/test_rekey.rb +41 -1
- data/test/core/hash/test_revalue.rb +98 -0
- data/test/core/hash/test_slice.rb +12 -1
- data/test/core/kernel/test_deep_clone.rb +31 -0
- data/test/core/kernel/test_deep_copy.rb +2 -28
- data/test/core/kernel/test_instance_extract.rb +28 -0
- data/test/core/method/test_composition.rb +42 -0
- data/test/core/range/test_op_add.rb +24 -0
- data/test/core/range/test_op_sub.rb +34 -0
- data/test/core/string/test_ascii_only.rb +30 -0
- data/test/core/string/test_margin.rb +4 -104
- data/test/core/string/test_number.rb +44 -0
- data/test/core/string/test_remove.rb +36 -0
- data/test/core/string/test_rotate.rb +31 -0
- data/test/core/string/test_trim.rb +116 -0
- data/test/core/symbol/test_thrown.rb +22 -0
- data/test/standard/binding/test_block_exec.rb +21 -0
- data/test/standard/math/test_acot.rb +23 -0
- data/test/standard/math/test_acoth.rb +22 -0
- data/test/standard/math/test_beta.rb +19 -0
- data/test/standard/math/test_ceil.rb +22 -0
- data/test/standard/math/test_cosec.rb +19 -0
- data/test/standard/math/test_cosech.rb +19 -0
- data/test/standard/math/test_cot.rb +13 -0
- data/test/standard/math/test_coth.rb +13 -0
- data/test/standard/math/test_distance.rb +16 -0
- data/test/standard/math/test_exp10.rb +14 -0
- data/test/standard/math/test_exp2.rb +14 -0
- data/test/standard/math/test_factorial.rb +13 -0
- data/test/standard/math/test_floor.rb +23 -0
- data/test/standard/math/test_gcd.rb +18 -0
- data/test/standard/math/test_lcm.rb +13 -0
- data/test/standard/math/test_pow.rb +30 -0
- data/test/standard/math/test_root.rb +15 -0
- data/test/standard/math/test_sec.rb +19 -0
- data/test/standard/math/test_sech.rb +19 -0
- data/test/standard/math/test_sign.rb +6 -0
- data/test/standard/math/test_sinc.rb +15 -0
- data/test/standard/math/test_srq.rb +20 -0
- data/test/standard/pathname/test_chdir.rb +16 -0
- data/test/standard/pathname/test_readline.rb +23 -0
- data/test/standard/test_enumargs.rb +1 -1
- data/test/standard/test_math.rb +3 -0
- data/test/standard/test_ostruct.rb +26 -21
- data/test/standard/test_uri.rb +9 -0
- metadata +802 -183
- data/.ruby +0 -54
- data/HISTORY.rdoc +0 -2386
- data/lib/core/facets/array/combination.rb +0 -43
- data/lib/core/facets/array/index.rb +0 -23
- data/lib/core/facets/array/occurent.rb +0 -1
- data/lib/core/facets/array/permutation.rb +0 -32
- data/lib/core/facets/array/product.rb +0 -30
- data/lib/core/facets/array/rotate.rb +0 -48
- data/lib/core/facets/array/select.rb +0 -20
- data/lib/core/facets/binding/eval.rb +0 -14
- data/lib/core/facets/enumerable/count.rb +0 -53
- data/lib/core/facets/enumerable/each_with_object.rb +0 -38
- data/lib/core/facets/enumerable/group_by.rb +0 -33
- data/lib/core/facets/enumerable/none.rb +0 -32
- data/lib/core/facets/enumerable/one.rb +0 -39
- data/lib/core/facets/enumerable/take.rb +0 -16
- data/lib/core/facets/float/round.rb +0 -2
- data/lib/core/facets/hash/select.rb +0 -17
- data/lib/core/facets/hash/to_h.rb +0 -1
- data/lib/core/facets/hash/url_params.rb +0 -21
- data/lib/core/facets/instance.rb +0 -157
- data/lib/core/facets/integer/even.rb +0 -1
- data/lib/core/facets/integer/odd.rb +0 -37
- data/lib/core/facets/kernel/__callee__.rb +0 -1
- data/lib/core/facets/kernel/__method__.rb +0 -48
- data/lib/core/facets/kernel/require_relative.rb +0 -52
- data/lib/core/facets/kernel/source_location.rb +0 -13
- data/lib/core/facets/nilclass/to_f.rb +0 -17
- data/lib/core/facets/numeric/round.rb +0 -69
- data/lib/core/facets/numeric/round_at.rb +0 -1
- data/lib/core/facets/object/replace.rb +0 -43
- data/lib/core/facets/objectspace/reflect.rb +0 -62
- data/lib/core/facets/proc/curry.rb +0 -32
- data/lib/core/facets/string/bytes.rb +0 -21
- data/lib/core/facets/string/each_char.rb +0 -31
- data/lib/core/facets/string/end_with.rb +0 -1
- data/lib/core/facets/string/lines.rb +0 -19
- data/lib/core/facets/string/random_binary.rb +0 -10
- data/lib/core/facets/string/start_with.rb +0 -60
- data/lib/core/facets/symbol/to_proc.rb +0 -33
- data/lib/core/facets/to_hash.rb +0 -336
- data/lib/core/facets/unboundmethod/name.rb +0 -28
- data/lib/standard/facets/math/gamma.rb +0 -12
- data/test/core/array/test_occurent.rb +0 -33
- data/test/core/kernel/test_source_location.rb +0 -25
- data/test/core/string/test_tabto.rb +0 -16
@@ -1 +0,0 @@
|
|
1
|
-
require 'facets/numeric/round'
|
@@ -1,43 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
|
3
|
-
# Replace state of object with the state of another object of the
|
4
|
-
# same class (or superclass).
|
5
|
-
#
|
6
|
-
# class ReplaceExample
|
7
|
-
# attr_reader :a, :b
|
8
|
-
# def initialize(a,b)
|
9
|
-
# @a, @b = a, b
|
10
|
-
# end
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# obj1 = ReplaceExample.new(1,2)
|
14
|
-
# obj1.a #=> 1
|
15
|
-
# obj1.b #=> 2
|
16
|
-
#
|
17
|
-
# obj2 = ReplaceExample.new(3,4)
|
18
|
-
# obj2.a #=> 3
|
19
|
-
# obj2.b #=> 4
|
20
|
-
#
|
21
|
-
# obj1.replace(obj2)
|
22
|
-
# obj1.a #=> 3
|
23
|
-
# obj1.b #=> 4
|
24
|
-
#
|
25
|
-
# This is very similar to <code>instance.update</code>, but it is limited
|
26
|
-
# by the class of objects, in the same manner as Array#replace.
|
27
|
-
def replace(source)
|
28
|
-
raise ArgumentError, "not a #{self.class} -- #{source}" unless source.is_a?(self.class)
|
29
|
-
instance_variables.each do |iv|
|
30
|
-
instance_variable_set(iv, source.instance_variable_get(iv))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
class Struct
|
37
|
-
|
38
|
-
# Struct#replace can take any +source+ that responds to #each_pair.
|
39
|
-
def replace(source)
|
40
|
-
source.each_pair{ |k,v| send(k.to_s + "=", v) }
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'facets/functor'
|
2
|
-
|
3
|
-
module ObjectSpace
|
4
|
-
|
5
|
-
# Reflection ensures that information about an object
|
6
|
-
# is actual according to Ruby's Kernel definitions, just
|
7
|
-
# in case such methods have been overridden.
|
8
|
-
#
|
9
|
-
# ObjectSpace.reflect("object").object_id
|
10
|
-
#
|
11
|
-
# There is also a global short-cut for this method to ease
|
12
|
-
# meta-programming with it.
|
13
|
-
#
|
14
|
-
# $ref["object"].class
|
15
|
-
#
|
16
|
-
# Typically theis method will be used to gather the object's
|
17
|
-
# id, as in the example given, or it's class, but any Kernel
|
18
|
-
# method can be used.
|
19
|
-
#
|
20
|
-
# Care should be taken in utilizing this technique. In most
|
21
|
-
# cases it is not needed, but in certain cases is useful
|
22
|
-
# for improving the robustness of meta-programming solutions.
|
23
|
-
#
|
24
|
-
# Note that this is also equivalent to using +as(Kernel)+ ...
|
25
|
-
#
|
26
|
-
# "object".as(Kernel).object_id
|
27
|
-
#
|
28
|
-
# But obviously, in this case there is the risk that #as has
|
29
|
-
# be overridden too.
|
30
|
-
#
|
31
|
-
def self.reflect(obj)
|
32
|
-
## TODO: use this after 1.8.6 support discontinued
|
33
|
-
## Functor.new do |op, *a, &b|
|
34
|
-
## Kernel.instance_method(op).bind(obj).call(*a, &b)
|
35
|
-
## end
|
36
|
-
Reflector.new(obj)
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
class Reflector #:nodoc:
|
41
|
-
instance_methods(true).each{ |m| private m unless /^(__|object_id$)/ =~ m.to_s }
|
42
|
-
|
43
|
-
def initialize(obj)
|
44
|
-
@obj = obj
|
45
|
-
end
|
46
|
-
|
47
|
-
def method_missing(op, *args, &yld)
|
48
|
-
Kernel.instance_method(op).bind(@obj).call(*args, &yld)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
# Shorcut for +ObjectSpace.reflect+.
|
55
|
-
$ref = lambda do |obj|
|
56
|
-
## TODO: use this after 1.8.6 support discontinued
|
57
|
-
## Functor.new do |meth, *a, &b|
|
58
|
-
## Kernel.instance_method(meth).bind(obj).call(*a, &b)
|
59
|
-
## end
|
60
|
-
ObjectSpace.reflect(obj)
|
61
|
-
end
|
62
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class Proc
|
2
|
-
|
3
|
-
# Curry Proc object into new Proc object.
|
4
|
-
#
|
5
|
-
# TODO: Utilize Ruby 1.9's #curry method.
|
6
|
-
|
7
|
-
def curry(*args)
|
8
|
-
if args.empty?
|
9
|
-
idx = (0...arity).to_a
|
10
|
-
else
|
11
|
-
raise ArgumentError, "argument count is greater than prok.arity (#{args.size} > #{arity})" if args.size > arity
|
12
|
-
raise ArgumentError, "arguments must be unique indexes" if args.uniq != args
|
13
|
-
raise ArgumentError, "arguments must be indexes" if args.any?{ |a| !Fixnum===a }
|
14
|
-
idx = (0...arity).to_a
|
15
|
-
idx = args + (idx - args)
|
16
|
-
end
|
17
|
-
|
18
|
-
pro = self
|
19
|
-
rec = ''
|
20
|
-
idx.each do |i|
|
21
|
-
rec << "proc { |a#{i}| "
|
22
|
-
end
|
23
|
-
rec << "pro["
|
24
|
-
rec << (0...arity).to_a.collect{|i| "a#{i}"}.join(',')
|
25
|
-
rec << "]"
|
26
|
-
rec << "}" * arity
|
27
|
-
|
28
|
-
instance_eval rec
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
unless method_defined?(:bytes) # 1.8.7+
|
4
|
-
|
5
|
-
# Upacks string into bytes.
|
6
|
-
#
|
7
|
-
# Note, this is not 100% compatible with 1.8.7+
|
8
|
-
# which returns an enumerator instead of an array.
|
9
|
-
#
|
10
|
-
def bytes(&blk)
|
11
|
-
if block_given?
|
12
|
-
self.unpack('C*').each(&blk)
|
13
|
-
else
|
14
|
-
self.unpack('C*')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
@@ -1,31 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
unless method_defined?(:each_char) # 1.9
|
4
|
-
|
5
|
-
require 'strscan'
|
6
|
-
|
7
|
-
# Yields a single-character string for each character in the string.
|
8
|
-
# When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
|
9
|
-
#
|
10
|
-
# a = ''
|
11
|
-
# "HELLO".each_char{ |c| a << "#{c.downcase}" }
|
12
|
-
# a #=> 'hello'
|
13
|
-
#
|
14
|
-
def each_char # :yield:
|
15
|
-
scanner, char = StringScanner.new(self), /./mu
|
16
|
-
loop{ yield(scanner.scan(char) || break) }
|
17
|
-
end
|
18
|
-
|
19
|
-
#--
|
20
|
-
# Iterates through each character. This is a little faster than
|
21
|
-
# using #chars b/c it does not create the intermediate array...
|
22
|
-
#
|
23
|
-
# def each_char # :yield:
|
24
|
-
# size.times{ |i| yield(self[i,1]) }
|
25
|
-
# end
|
26
|
-
#++
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'facets/string/start_with'
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
unless method_defined?(:lines) # 1.8.7+
|
4
|
-
|
5
|
-
# Returns an array of characters.
|
6
|
-
#
|
7
|
-
# "abc\n123".lines.to_a #=> ["abc\n","123"]
|
8
|
-
#
|
9
|
-
def lines(&blk)
|
10
|
-
if block_given?
|
11
|
-
each_line(&blk) #scan(/$.*?\n/).each(&blk)
|
12
|
-
else
|
13
|
-
Enumerator.new(self, :lines) #.split(/\n/)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# = Developer's Notes
|
3
|
-
#
|
4
|
-
# Old definition of start_with? written by Lucas Carlson
|
5
|
-
# and Blaine Cook was ...
|
6
|
-
#
|
7
|
-
# index(prefix) == 0
|
8
|
-
#
|
9
|
-
# I like the simplicity of this definition, but I could not
|
10
|
-
# find a way define #end_with? in similar terms and still
|
11
|
-
# accept regular expressions for the suffix. So I had to use
|
12
|
-
# Regexp match. On th upside, we can get MatchData
|
13
|
-
# which might be more useful.
|
14
|
-
#++
|
15
|
-
|
16
|
-
class String
|
17
|
-
|
18
|
-
#unless method_defined?(:start_with?) # 1.8.7+
|
19
|
-
|
20
|
-
# Does a string start with the given prefix?
|
21
|
-
#
|
22
|
-
# "hello".start_with?("he") #=> true
|
23
|
-
# "hello".start_with?("to") #=> false
|
24
|
-
#
|
25
|
-
# Note: This definition is better than standard Ruby's
|
26
|
-
# becuase it handles regular expressions.
|
27
|
-
#
|
28
|
-
# CREDIT: Juris Galang
|
29
|
-
|
30
|
-
def start_with?(prefix)
|
31
|
-
prefix = Regexp.escape(prefix.to_s) unless Regexp===prefix
|
32
|
-
/^#{prefix}/.match(self) ? true : false
|
33
|
-
end
|
34
|
-
|
35
|
-
#end
|
36
|
-
|
37
|
-
#unless method_defined?(:end_with?) # 1.8.7+
|
38
|
-
|
39
|
-
# Does a string end with the given suffix?
|
40
|
-
#
|
41
|
-
# "hello".end_with?("lo") #=> true
|
42
|
-
# "hello".end_with?("to") #=> false
|
43
|
-
#
|
44
|
-
# Note: This definition is better than standard Ruby's
|
45
|
-
# becuase it handles regular expressions.
|
46
|
-
#
|
47
|
-
# CREDIT: Juris Galang
|
48
|
-
|
49
|
-
def end_with?(suffix)
|
50
|
-
suffix = Regexp.escape(suffix.to_s) unless Regexp===suffix
|
51
|
-
/#{suffix}$/.match(self) ? true : false
|
52
|
-
end
|
53
|
-
|
54
|
-
#end
|
55
|
-
|
56
|
-
alias_method :starts_with?, :start_with?
|
57
|
-
alias_method :ends_with? , :end_with?
|
58
|
-
|
59
|
-
end
|
60
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
class Symbol
|
2
|
-
|
3
|
-
unless method_defined?(:to_proc) # 1.8.7+
|
4
|
-
|
5
|
-
# Turn a symbol into a proc calling the method to which it refers.
|
6
|
-
#
|
7
|
-
# up = :upcase.to_proc
|
8
|
-
# up.call("hello") #=> 'HELLO'
|
9
|
-
#
|
10
|
-
# More useful is the fact that this allows <tt>&</tt>
|
11
|
-
# to be used to coerce Symbol into Proc.
|
12
|
-
#
|
13
|
-
# %w{foo bar qux}.map(&:upcase) #=> ["FOO","BAR","QUX"]
|
14
|
-
# [1, 2, 3].inject(&:+) #=> 6
|
15
|
-
#
|
16
|
-
# TODO: This will be deprecated as of Ruby 1.9, since it will become standard Ruby.
|
17
|
-
#
|
18
|
-
# CREDIT: Florian Gross (orignal), Nobuhiro Imai (current)
|
19
|
-
|
20
|
-
def to_proc
|
21
|
-
Proc.new{|*args| args.shift.__send__(self, *args)}
|
22
|
-
end
|
23
|
-
|
24
|
-
# Old Definition...
|
25
|
-
#
|
26
|
-
# def to_proc
|
27
|
-
# proc { |obj, *args| obj.send(self, *args) }
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
data/lib/core/facets/to_hash.rb
DELETED
@@ -1,336 +0,0 @@
|
|
1
|
-
require 'facets/enumerator'
|
2
|
-
require 'facets/hash/dearray_values'
|
3
|
-
|
4
|
-
class Array
|
5
|
-
|
6
|
-
# Converts an array into a hash. Converting an array
|
7
|
-
# into a hash is not a one-to-one conversion, for this
|
8
|
-
# reason #to_h examines at the array being converted
|
9
|
-
# and then dispatches the conversion to the most sutiable
|
10
|
-
# specialized function. There are three possiblities for this.
|
11
|
-
#
|
12
|
-
# If the array is a collection of perfect pairs, like that
|
13
|
-
# which Hash#to_a generates, then conversion is handled by
|
14
|
-
# #to_h_flat.
|
15
|
-
#
|
16
|
-
# a = [ [:a,1], [:b,2] ]
|
17
|
-
# a.to_h #=> { :a=>1, :b=>2 }
|
18
|
-
#
|
19
|
-
# If the array contains only arrays, but are not perfect pairs,
|
20
|
-
# then #to_h_multi is called.
|
21
|
-
#
|
22
|
-
# a = [ [:a,1,2], [:b,2], [:c], [:d] ]
|
23
|
-
# a.to_h #=> { :a=>[1,2], :b=>[2], :c=>[], :d=>[] }
|
24
|
-
#
|
25
|
-
# If the array contians objects other then arrays then
|
26
|
-
# the #to_h_splat method is called.
|
27
|
-
#
|
28
|
-
# a = [ [:a,1,2], 2, :b, [:c,3], 9 ]
|
29
|
-
# a.to_h #=> { [:a,1,2]=>2, :b=>[:c,3], 9=>nil }
|
30
|
-
#
|
31
|
-
# Finally, a particular dispatch can be forced by
|
32
|
-
# specifying the +mode+ of conversion, eg. +:multi+,
|
33
|
-
# +:splat+, +:flat+, +:assoc+, etc.
|
34
|
-
#
|
35
|
-
# Setting +mode+ to +true+ is the same as setting it +:multi+.
|
36
|
-
# This has been left in for backward compatability.
|
37
|
-
#
|
38
|
-
# NOTE: The use of a +values+ parameter has been deprecated
|
39
|
-
# because that functionality is as simple as ...
|
40
|
-
#
|
41
|
-
# array1.zip(array2).to_h
|
42
|
-
#
|
43
|
-
# CREDIT: Robert Klemme, Trans
|
44
|
-
#
|
45
|
-
#--
|
46
|
-
# The +True+ option in the case statement provides some
|
47
|
-
# backward compatability with the previous versions of this
|
48
|
-
# method.
|
49
|
-
#++
|
50
|
-
|
51
|
-
def to_h(mode=nil)
|
52
|
-
case mode
|
53
|
-
when :splat
|
54
|
-
return to_h_splat
|
55
|
-
when :flat
|
56
|
-
return to_h_flat
|
57
|
-
when :multi, true
|
58
|
-
return to_h_multi
|
59
|
-
when :assoc
|
60
|
-
return to_h_assoc
|
61
|
-
else
|
62
|
-
return to_h_auto
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Converts an array into a hash. Converting an array
|
67
|
-
# into a hash is not a one-to-one conversion, for this
|
68
|
-
# reason #to_h examines at the array being converted
|
69
|
-
# and then dispatches the conversion to the most sutiable
|
70
|
-
# specialized function. There are three possiblities for this.
|
71
|
-
#
|
72
|
-
# If the array is a collection of perfect pairs, like that
|
73
|
-
# which Hash#to_a generates, then conversion is handled by
|
74
|
-
# #to_h_flat.
|
75
|
-
#
|
76
|
-
# a = [ [:a,1], [:b,2] ]
|
77
|
-
# a.to_h_auto #=> { :a=>1, :b=>2 }
|
78
|
-
#
|
79
|
-
# If the array contains only arrays, but are not perfect pairs,
|
80
|
-
# then #to_h_multi is called.
|
81
|
-
#
|
82
|
-
# a = [ [:a,1,2], [:b,2], [:c], [:d] ]
|
83
|
-
# a.to_h_auto #=> { :a=>[1,2], :b=>[2], :c=>[], :d=>[] }
|
84
|
-
#
|
85
|
-
# If the array contians objects other then arrays then
|
86
|
-
# the #to_h_splat method is called.
|
87
|
-
#
|
88
|
-
# a = [ [:a,1,2], 2, :b, [:c,3], 9 ]
|
89
|
-
# a.to_h_auto #=> { [:a,1,2]=>2, :b=>[:c,3], 9=>nil }
|
90
|
-
#
|
91
|
-
def to_h_auto
|
92
|
-
pairs = true
|
93
|
-
mixed = false
|
94
|
-
|
95
|
-
each do |e|
|
96
|
-
case e
|
97
|
-
when Array
|
98
|
-
pairs = false if e.size > 2
|
99
|
-
else
|
100
|
-
mixed = true
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
if mixed
|
105
|
-
to_h_splat
|
106
|
-
elsif pairs
|
107
|
-
to_h_flat
|
108
|
-
else
|
109
|
-
to_h_multi
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# This is equivalent to Hash[*array], but it will pad
|
114
|
-
# the array with a +nil+ object if there are not an even number
|
115
|
-
# of elements.
|
116
|
-
#
|
117
|
-
# a = [:a,1,:b,2,:c]
|
118
|
-
# a.to_h_splat #=> { :a=>1, :b=>2, :c=>nil }
|
119
|
-
#
|
120
|
-
def to_h_splat
|
121
|
-
a = dup
|
122
|
-
a << nil if a.size % 2 == 1
|
123
|
-
Hash[*a]
|
124
|
-
end
|
125
|
-
|
126
|
-
# This is equivalent to Hash[*array.flatten], but it will pad
|
127
|
-
# the array with a +nil+ object if there are not an even number
|
128
|
-
# of elements.
|
129
|
-
#
|
130
|
-
# a = [:a,1,[:b,2,:c]]
|
131
|
-
# a.to_h_flat #=> { :a=>1, :b=>2, :c=>nil }
|
132
|
-
#
|
133
|
-
def to_h_flat
|
134
|
-
a = flatten
|
135
|
-
a << nil if a.size % 2 == 1
|
136
|
-
Hash[*a]
|
137
|
-
end
|
138
|
-
|
139
|
-
#--
|
140
|
-
#def to_h_flat
|
141
|
-
# each_slice(2).inject({}) {|ha,(k,v)| ha[k]=v; ha}
|
142
|
-
#end
|
143
|
-
#++
|
144
|
-
|
145
|
-
# When a mixed or multi-element accociative array
|
146
|
-
# is used, the result is as follows:
|
147
|
-
#
|
148
|
-
# a = [ [:a,1,2], [:b,2], [:c], :d ]
|
149
|
-
# a.to_h #=> { :a=>[1,2], :b=>[2], :c=>[], :d=>[] }
|
150
|
-
#
|
151
|
-
# If the first entry of any subelements are the same, then
|
152
|
-
# the value will be set to the last occuring value.
|
153
|
-
#
|
154
|
-
# a = [ :x, [:x], [:x,1,2], [:x,3], [:x,4] ]
|
155
|
-
# a.to_h_assoc #=> { :x=>[4] }
|
156
|
-
#
|
157
|
-
def to_h_assoc
|
158
|
-
h = {}
|
159
|
-
each do |k,*v|
|
160
|
-
h[k] = v
|
161
|
-
end
|
162
|
-
h
|
163
|
-
end
|
164
|
-
|
165
|
-
# When a mixed or multi-element accociative array
|
166
|
-
# is used, the result is as follows:
|
167
|
-
#
|
168
|
-
# a = [ [:a,1,2], [:b,2], [:c], :d ]
|
169
|
-
# a.to_h #=> { :a=>[1,2], :b=>[2], :c=>[], :d=>[] }
|
170
|
-
#
|
171
|
-
# If the first entry of the subelements is the same, then
|
172
|
-
# the values will be merged using #concat.
|
173
|
-
#
|
174
|
-
# a = [ [:a,1,2], [:a,3], [:a,4], [:a], :a ]
|
175
|
-
# a.to_h_multi #=> { :a=>[1,2,3,4] }
|
176
|
-
#
|
177
|
-
def to_h_multi
|
178
|
-
h = {}
|
179
|
-
each do |k,*v|
|
180
|
-
h[k] ||= []
|
181
|
-
h[k].concat(v)
|
182
|
-
end
|
183
|
-
h
|
184
|
-
end
|
185
|
-
|
186
|
-
#--
|
187
|
-
#def to_h_multi
|
188
|
-
# inject({}) {|h,a| h[a.first] = a[1..-1]; h}
|
189
|
-
#end
|
190
|
-
|
191
|
-
# Is this a good idea?
|
192
|
-
#def to_hash
|
193
|
-
# h = {}
|
194
|
-
# each_with_index do |v, i|
|
195
|
-
# h[i] = v
|
196
|
-
# end
|
197
|
-
# h
|
198
|
-
#end
|
199
|
-
#++
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
class Hash
|
204
|
-
|
205
|
-
# Return a rehashing of _self_.
|
206
|
-
#
|
207
|
-
# {"a"=>1,"b"=>2}.to_h #=> {"b"=>2,"a"=>1}
|
208
|
-
#
|
209
|
-
# CREDIT: Forian Gross
|
210
|
-
|
211
|
-
def to_h; rehash; end
|
212
|
-
|
213
|
-
unless method_defined?(:to_hash) # 1.9.?+
|
214
|
-
# Returns _self_.
|
215
|
-
def to_hash; self; end
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
module Enumerable
|
221
|
-
|
222
|
-
# Convert an Enumerable object into a hash by first
|
223
|
-
# turning it into an array.
|
224
|
-
#
|
225
|
-
# CREDIT: Trans
|
226
|
-
|
227
|
-
def to_h(mode=nil)
|
228
|
-
to_a.to_h(mode)
|
229
|
-
end
|
230
|
-
|
231
|
-
def to_h_auto
|
232
|
-
to_a.to_h_auto
|
233
|
-
end
|
234
|
-
|
235
|
-
def to_h_splat
|
236
|
-
to_a.to_h_splat
|
237
|
-
end
|
238
|
-
|
239
|
-
def to_h_flat
|
240
|
-
to_a.to_h_flat
|
241
|
-
end
|
242
|
-
|
243
|
-
def to_h_assoc
|
244
|
-
to_a.to_h_assoc
|
245
|
-
end
|
246
|
-
|
247
|
-
def to_h_multi
|
248
|
-
to_a.to_h_multi
|
249
|
-
end
|
250
|
-
|
251
|
-
#--
|
252
|
-
#def to_hash
|
253
|
-
# to_a.to_hash
|
254
|
-
#end
|
255
|
-
#++
|
256
|
-
|
257
|
-
end
|
258
|
-
|
259
|
-
class NilClass
|
260
|
-
|
261
|
-
# Allows <tt>nil</tt> to create an empty hash,
|
262
|
-
# similar to #to_a and #to_s.
|
263
|
-
#
|
264
|
-
# nil.to_h #=> {}
|
265
|
-
#
|
266
|
-
# CREDIT: Trans
|
267
|
-
|
268
|
-
def to_h; {}; end
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
|
273
|
-
class Enumerator
|
274
|
-
|
275
|
-
# Convert an Enumerator object into a hash.
|
276
|
-
# This is equivalent to Array#to_h.
|
277
|
-
#
|
278
|
-
# e1 = [[1,:a],[2,:b],[3,:c]].to_enum
|
279
|
-
# e1.to_h #=> { 1=>:a, 2=>:b, 3=>:c }
|
280
|
-
#
|
281
|
-
# e2 = [1,2,3,4,5].to_enum
|
282
|
-
# e2.to_h #=> {5=>nil, 1=>2, 3=>4}
|
283
|
-
#
|
284
|
-
# e3 = [1,2,1,3,1,5].to_enum
|
285
|
-
# e3.to_h #=> {1=>5}
|
286
|
-
#
|
287
|
-
# CREDIT: Sandor Szücs
|
288
|
-
|
289
|
-
def to_h(mode=nil)
|
290
|
-
to_a.to_h(mode)
|
291
|
-
end
|
292
|
-
|
293
|
-
# This is equivalent to Array#to_h_auto.
|
294
|
-
#
|
295
|
-
def to_h_auto
|
296
|
-
to_a.to_h_auto
|
297
|
-
end
|
298
|
-
|
299
|
-
# This is equivalent to Array#to_h_splat.
|
300
|
-
#
|
301
|
-
def to_h_splat
|
302
|
-
to_a.to_h_splat
|
303
|
-
end
|
304
|
-
|
305
|
-
# This is equivalent to Array#to_h_flat.
|
306
|
-
#
|
307
|
-
def to_h_flat
|
308
|
-
to_a.to_h_flat
|
309
|
-
end
|
310
|
-
|
311
|
-
# This is equivalent to Array#to_h_assoc.
|
312
|
-
#
|
313
|
-
def to_h_assoc
|
314
|
-
to_a.to_h_assoc
|
315
|
-
end
|
316
|
-
|
317
|
-
# This is equivalent to Array#to_h_multi.
|
318
|
-
#
|
319
|
-
def to_h_multi
|
320
|
-
to_a.to_h_multi
|
321
|
-
end
|
322
|
-
|
323
|
-
end
|
324
|
-
|
325
|
-
class Struct
|
326
|
-
|
327
|
-
# Returns a hash containing the names and values
|
328
|
-
# for all instance settings in the Struct.
|
329
|
-
def to_h
|
330
|
-
h = {}
|
331
|
-
each_pair{ |k,v| h[k] = v }
|
332
|
-
h
|
333
|
-
end
|
334
|
-
|
335
|
-
end
|
336
|
-
|