facets 3.0.0 → 3.2.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 +5 -5
- data/CONTRIBUTING.md +112 -0
- data/HISTORY.md +179 -0
- data/LICENSE.txt +21 -343
- data/{README.rdoc → README.md} +74 -67
- data/lib/core/facets/array/arrange.rb +1 -42
- data/lib/core/facets/array/average.rb +15 -0
- data/lib/core/facets/array/before.rb +1 -1
- data/lib/core/facets/array/collapse.rb +4 -0
- data/lib/core/facets/array/delete_first.rb +21 -0
- data/lib/core/facets/array/delete_values_at.rb +1 -0
- data/lib/core/facets/array/divide.rb +7 -0
- data/lib/core/facets/array/duplicates.rb +15 -0
- data/lib/core/facets/array/each_pair.rb +1 -4
- data/lib/core/facets/array/first.rb +1 -0
- data/lib/core/facets/array/from.rb +11 -16
- data/lib/core/facets/array/indexes.rb +113 -0
- data/lib/core/facets/array/last.rb +1 -0
- data/lib/core/facets/array/mode.rb +2 -2
- data/lib/core/facets/array/nonuniq.rb +6 -8
- data/lib/core/facets/array/occurrence.rb +8 -4
- data/lib/core/facets/array/probability.rb +1 -1
- data/lib/core/facets/array/recursively.rb +2 -2
- data/lib/core/facets/array/remove.rb +39 -0
- data/lib/core/facets/array/span.rb +29 -0
- data/lib/core/facets/array/splice.rb +1 -1
- data/lib/core/facets/array/split_at.rb +25 -0
- data/lib/core/facets/array/standard_deviation.rb +28 -0
- data/lib/core/facets/array/step.rb +12 -14
- data/lib/core/facets/array/to_ranges.rb +48 -0
- data/lib/core/facets/array/uniq_by.rb +7 -3
- data/lib/core/facets/array/variance.rb +20 -0
- data/lib/core/facets/array.rb +1 -0
- data/lib/core/facets/binding/caller.rb +8 -2
- data/lib/core/facets/binding/op_get.rb +7 -11
- data/lib/core/facets/binding/self.rb +4 -10
- data/lib/core/facets/binding.rb +0 -1
- data/lib/core/facets/boolean.rb +1 -1
- data/lib/core/facets/class/descendants.rb +0 -2
- data/lib/core/facets/class.rb +2 -2
- data/lib/core/facets/comparable/bound.rb +13 -1
- data/lib/core/facets/comparable/clip.rb +3 -32
- data/lib/core/facets/denumerable.rb +0 -3
- data/lib/core/facets/dir/find.rb +20 -0
- data/lib/core/facets/dir/recurse.rb +8 -26
- data/lib/core/facets/enumerable/cluster.rb +6 -4
- data/lib/core/facets/enumerable/compact_map.rb +2 -12
- data/lib/core/facets/enumerable/defer.rb +2 -13
- data/lib/core/facets/enumerable/each_by.rb +0 -2
- data/lib/core/facets/enumerable/frequency.rb +2 -2
- data/lib/core/facets/enumerable/hashify.rb +27 -31
- data/lib/core/facets/enumerable/hinge.rb +3 -4
- data/lib/core/facets/enumerable/map_with_index.rb +3 -6
- data/lib/core/facets/enumerable/mash.rb +5 -28
- data/lib/core/facets/enumerable/uniq_by.rb +4 -8
- data/lib/core/facets/enumerable/with_position.rb +58 -0
- data/lib/core/facets/enumerator.rb +2 -75
- data/lib/core/facets/exception/error_print.rb +6 -71
- data/lib/core/facets/file/atomic_open.rb +1 -1
- data/lib/core/facets/file/null.rb +3 -15
- data/lib/core/facets/file/read_binary.rb +3 -12
- data/lib/core/facets/hash/except.rb +11 -6
- data/lib/core/facets/hash/fetch_nested.rb +8 -9
- data/lib/core/facets/hash/graph.rb +1 -1
- data/lib/core/facets/hash/rekey.rb +3 -3
- data/lib/core/facets/hash/revalue.rb +3 -3
- data/lib/core/facets/hash/{to_proc.rb → setter.rb} +8 -9
- data/lib/core/facets/hash/slice.rb +0 -26
- data/lib/core/facets/hash/update_keys.rb +4 -11
- data/lib/core/facets/hash/update_values.rb +4 -10
- data/lib/core/facets/indexable.rb +7 -5
- data/lib/core/facets/kernel/callstack.rb +5 -24
- data/lib/core/facets/kernel/eigenclass.rb +6 -6
- data/lib/core/facets/kernel/ergo.rb +3 -3
- data/lib/core/facets/kernel/extension.rb +3 -6
- data/lib/core/facets/kernel/functor.rb +16 -0
- data/lib/core/facets/kernel/instance_class.rb +4 -20
- data/lib/core/facets/kernel/instance_send.rb +5 -3
- data/lib/core/facets/kernel/like.rb +1 -1
- data/lib/core/facets/kernel/load_relative.rb +8 -20
- data/lib/core/facets/kernel/memo.rb +4 -26
- data/lib/core/facets/kernel/meta_class.rb +10 -6
- data/lib/core/facets/kernel/object_class.rb +5 -6
- data/lib/core/facets/kernel/object_send.rb +5 -26
- data/lib/core/facets/kernel/qua_class.rb +4 -20
- data/lib/core/facets/kernel/require_all.rb +8 -20
- data/lib/core/facets/kernel/returning.rb +3 -19
- data/lib/core/facets/kernel/tap.rb +3 -36
- data/lib/core/facets/kernel/tee.rb +2 -0
- data/lib/core/facets/kernel/try.rb +38 -28
- data/lib/core/facets/kernel.rb +2 -4
- data/lib/core/facets/lazy.rb +1 -1
- data/lib/core/facets/matchdata/matchtree.rb +2 -0
- data/lib/core/facets/module/alias_method_chain.rb +4 -43
- data/lib/core/facets/module/attr_setter.rb +3 -2
- data/lib/core/facets/module/can.rb +5 -16
- data/lib/core/facets/module/class_extend.rb +2 -2
- data/lib/core/facets/numeric/delimit.rb +20 -0
- data/lib/core/facets/object/dup.rb +0 -46
- data/lib/core/facets/proc/bind.rb +0 -2
- data/lib/core/facets/proc/compose.rb +7 -28
- data/lib/core/facets/proc/to_method.rb +0 -1
- data/lib/core/facets/proc/update.rb +8 -1
- data/lib/core/facets/range/intersection.rb +42 -0
- data/lib/core/facets/range/nudge.rb +27 -0
- data/lib/core/facets/string/ascii_only.rb +2 -2
- data/lib/core/facets/string/cleanlines.rb +0 -2
- data/lib/core/facets/string/dashcase.rb +21 -0
- data/lib/core/facets/string/indent.rb +0 -8
- data/lib/core/facets/string/lchomp.rb +7 -14
- data/lib/core/facets/string/margin.rb +0 -4
- data/lib/core/facets/string/newlines.rb +0 -2
- data/lib/core/facets/string/random.rb +13 -3
- data/lib/core/facets/string/similarity.rb +7 -6
- data/lib/core/facets/string/snakecase.rb +12 -5
- data/lib/core/facets/string/words.rb +13 -1
- data/lib/core/facets/string.rb +0 -3
- data/lib/core/facets/struct/attributes.rb +2 -3
- data/lib/core/facets/time/trunc.rb +12 -5
- data/lib/core/facets/unboundmethod/arguments.rb +1 -0
- data/lib/core/facets/version.rb +1 -17
- data/lib/core/facets.rb +0 -1
- data/lib/standard/facets/argvector.rb +1 -1
- data/lib/standard/facets/cgi/escape_html.rb +14 -25
- data/lib/standard/facets/cloneable.rb +4 -51
- data/lib/standard/facets/continuation.rb +2 -56
- data/lib/standard/facets/crypt3.rb +126 -0
- data/lib/standard/facets/date/cmp.rb +32 -0
- data/lib/standard/facets/date.rb +1 -0
- data/lib/standard/facets/digest.rb +0 -1
- data/lib/standard/facets/enumargs.rb +5 -0
- data/lib/standard/facets/fileutils/cp_rx.rb +0 -2
- data/lib/standard/facets/fileutils/ln_r.rb +0 -1
- data/lib/standard/facets/find/select.rb +0 -2
- data/lib/standard/facets/getoptlong.rb +3 -59
- data/lib/standard/facets/load_monitor.rb +2 -26
- data/lib/standard/facets/math/gini_coefficient.rb +5 -4
- data/lib/standard/facets/math/kldivergence.rb +8 -7
- data/lib/standard/facets/math/percentile.rb +2 -2
- data/lib/standard/facets/multiton.rb +1 -1
- data/lib/standard/facets/net/http.rb +33 -14
- data/lib/standard/facets/ostruct/initialize.rb +4 -19
- data/lib/standard/facets/ostruct/to_ostruct.rb +2 -1
- data/lib/standard/facets/ostruct.rb +0 -88
- data/lib/standard/facets/pathname/empty.rb +2 -10
- data/lib/standard/facets/pathname/glob.rb +19 -12
- data/lib/standard/facets/pathname/null.rb +3 -14
- data/lib/standard/facets/random.rb +47 -133
- data/lib/standard/facets/timer.rb +3 -3
- data/lib/standard/facets/tuple.rb +2 -4
- data/lib/standard/facets/uri.rb +3 -2
- metadata +84 -1181
- data/.index +0 -76
- data/.yardopts +0 -10
- data/CONTRIBUTE.md +0 -78
- data/NOTICE.rdoc +0 -167
- data/demo/applique/assertion_framework.rb +0 -1
- data/demo/applique/file_helpers.rb +0 -34
- data/demo/core/array/combination.rdoc +0 -19
- data/demo/core/array/delete.rdoc +0 -23
- data/demo/core/array/index.rdoc +0 -14
- data/demo/core/array/merge.rdoc +0 -15
- data/demo/core/array/only.rdoc +0 -9
- data/demo/core/array/pad.rdoc +0 -28
- data/demo/core/array/permutation.rdoc +0 -10
- data/demo/core/array/product.rdoc +0 -26
- data/demo/core/array/recursively.rdoc +0 -16
- data/demo/core/array/rotate.rdoc +0 -30
- data/demo/core/array/select.rdoc +0 -8
- data/demo/core/array/uniq_by.rdoc +0 -9
- data/demo/core/binding/caller.rdoc +0 -57
- data/demo/core/binding/defined.rdoc +0 -10
- data/demo/core/binding/eval.rdoc +0 -8
- data/demo/core/binding/local_variables.rdoc +0 -26
- data/demo/core/binding/opvars.rdoc +0 -16
- data/demo/core/binding/self.rdoc +0 -6
- data/demo/core/class/descendants.rdoc +0 -10
- data/demo/core/class/to_proc.rdoc +0 -8
- data/demo/core/comparable/cap.rdoc +0 -20
- data/demo/core/comparable/clip.rdoc +0 -37
- data/demo/core/comparable/cmp.rdoc +0 -18
- data/demo/core/comparable/op_get.rdoc +0 -29
- data/demo/core/dir/ascend.rdoc +0 -24
- data/demo/core/dir/descend.rdoc +0 -14
- data/demo/core/dir/multiglob.rdoc +0 -41
- data/demo/core/dir/parent.rdoc +0 -6
- data/demo/core/dir/recurse.rdoc +0 -41
- data/demo/core/exception/detail.rdoc +0 -12
- data/demo/core/facets.rdoc +0 -6
- data/demo/core/filetest/root.rdoc +0 -6
- data/demo/core/hash/recursively.rdoc +0 -21
- data/demo/core/indexable.rdoc +0 -95
- data/demo/core/integer/bitmask.rdoc +0 -46
- data/demo/core/integer/even.rdoc +0 -12
- data/demo/core/integer/factorial.rdoc +0 -10
- data/demo/core/integer/length.rdoc +0 -7
- data/demo/core/integer/multiple.rdoc +0 -10
- data/demo/core/integer/odd.rdoc +0 -12
- data/demo/core/integer/of.rdoc +0 -14
- data/demo/core/integer/ordinal.rdoc +0 -9
- data/demo/core/matchdata/match.rdoc +0 -7
- data/demo/core/matchdata/matchset.rdoc +0 -15
- data/demo/core/module/cattr.rdoc +0 -43
- data/demo/core/module/class_extend.rdoc +0 -64
- data/demo/core/module/class_inheritor.rdoc +0 -126
- data/demo/core/module/copy_inheritor.rdoc +0 -30
- data/demo/core/module/method_space.rdoc +0 -55
- data/demo/core/string/align.rdoc +0 -34
- data/demo/core/string/bracket.rdoc +0 -35
- data/demo/core/string/bytes.rdoc +0 -8
- data/demo/core/string/camelcase.rdoc +0 -47
- data/demo/core/string/capitalized.rdoc +0 -27
- data/demo/core/string/characters.rdoc +0 -11
- data/demo/core/string/cleanlines.rdoc +0 -10
- data/demo/core/string/cleave.rdoc +0 -49
- data/demo/core/string/divide.rdoc +0 -9
- data/demo/core/string/each_char.rdoc +0 -9
- data/demo/core/string/each_word.rdoc +0 -9
- data/demo/core/string/end_with.rdoc +0 -6
- data/demo/core/string/expand_tabs.rdoc +0 -69
- data/demo/core/string/fold.rdoc +0 -14
- data/demo/core/string/indent.rdoc +0 -65
- data/demo/core/string/interpolate.rdoc +0 -7
- data/demo/core/string/lchomp.rdoc +0 -14
- data/demo/core/string/line_wrap.rdoc +0 -7
- data/demo/core/string/lines.rdoc +0 -8
- data/demo/core/string/margin.rdoc +0 -92
- data/demo/core/string/methodize.rdoc +0 -22
- data/demo/core/string/modulize.rdoc +0 -22
- data/demo/core/string/mscan.rdoc +0 -10
- data/demo/core/string/natcmp.rdoc +0 -10
- data/demo/core/string/nchar.rdoc +0 -9
- data/demo/core/string/newlines.rdoc +0 -9
- data/demo/core/string/op_sub.rdoc +0 -7
- data/demo/core/string/pathize.rdoc +0 -22
- data/demo/core/string/quote.rdoc +0 -20
- data/demo/core/string/range.rdoc +0 -19
- data/demo/core/string/rewrite.rdoc +0 -9
- data/demo/core/string/shatter.rdoc +0 -9
- data/demo/core/string/snakecase.rdoc +0 -10
- data/demo/core/string/splice.rdoc +0 -28
- data/demo/core/string/start_with.rdoc +0 -7
- data/demo/core/string/subtract.rdoc +0 -8
- data/demo/core/string/tab.rdoc +0 -16
- data/demo/core/string/tabto.rdoc +0 -29
- data/demo/core/string/titlecase.rdoc +0 -8
- data/demo/core/string/to_re.rdoc +0 -22
- data/demo/core/string/unfold.rdoc +0 -9
- data/demo/core/string/unindent.rdoc +0 -65
- data/demo/core/string/unquote.rdoc +0 -6
- data/demo/core/string/variablize.rdoc +0 -7
- data/demo/core/string/word_wrap.rdoc +0 -54
- data/demo/core/string/words.rdoc +0 -13
- data/demo/core/string/xor.rdoc +0 -8
- data/demo/standard/02_cloneable.rdoc +0 -46
- data/demo/standard/03_enumargs.rdoc +0 -75
- data/demo/standard/04_equitable.rdoc +0 -35
- data/demo/standard/05_instantiable.rdoc +0 -42
- data/demo/standard/basic_object.rdoc +0 -22
- data/demo/standard/memoizable.rdoc +0 -134
- data/demo/standard/mulititon.rdoc +0 -156
- data/lib/core/facets/applique/file_helpers.rb +0 -33
- data/lib/core/facets/array/intersection.rb +0 -25
- data/lib/core/facets/array/op_pow.rb +0 -14
- data/lib/core/facets/array/to_h.rb +0 -22
- data/lib/core/facets/binding/local_variables.rb +0 -16
- data/lib/core/facets/class/singleton.rb +0 -1
- data/lib/core/facets/class/singleton_class.rb +0 -16
- data/lib/core/facets/class/subclasses.rb +0 -28
- data/lib/core/facets/dir/each_child.rb +0 -16
- data/lib/core/facets/enumerable/filter.rb +0 -33
- data/lib/core/facets/enumerable/sum.rb +0 -30
- data/lib/core/facets/exception/set_message.rb +0 -10
- data/lib/core/facets/file/write.rb +0 -24
- data/lib/core/facets/fixnum.rb +0 -7
- data/lib/core/facets/kernel/__dir__.rb +0 -28
- data/lib/core/facets/kernel/constant.rb +0 -22
- data/lib/core/facets/kernel/instance_exec.rb +0 -47
- data/lib/core/facets/kernel/p.rb +0 -24
- data/lib/core/facets/kernel/singleton_class.rb +0 -10
- data/lib/core/facets/matchdata/match.rb +0 -15
- data/lib/core/facets/method/curry.rb +0 -13
- data/lib/core/facets/numeric/negative.rb +0 -1
- data/lib/core/facets/numeric/positive.rb +0 -15
- data/lib/core/facets/object/itself.rb +0 -16
- data/lib/core/facets/object/try_dup.rb +0 -1
- data/lib/core/facets/process/daemon.rb +0 -32
- data/lib/core/facets/range/overlap.rb +0 -12
- data/lib/core/facets/string/characters.rb +0 -13
- data/lib/core/facets/string/crypt.rb +0 -22
- data/lib/core/facets/string/tab.rb +0 -2
- data/lib/core/facets/string/tabto.rb +0 -2
- data/lib/core/facets/symbol/succ.rb +0 -23
- data/lib/core/facets.yml +0 -76
- data/lib/standard/facets/basicobject.rb +0 -75
- data/lib/standard/facets/digest/base64digest.rb +0 -45
- data/lib/standard/facets/ostruct/each.rb +0 -11
- data/lib/standard/facets/ostruct/merge.rb +0 -21
- data/lib/standard/facets/ostruct/op_fetch.rb +0 -29
- data/lib/standard/facets/ostruct/op_store.rb +0 -1
- data/lib/standard/facets/ostruct/to_h.rb +0 -10
- data/test/core/array/test_after.rb +0 -27
- data/test/core/array/test_arrange.rb +0 -37
- data/test/core/array/test_before.rb +0 -27
- data/test/core/array/test_collapse.rb +0 -14
- data/test/core/array/test_combination.rb +0 -25
- data/test/core/array/test_commonality.rb +0 -35
- data/test/core/array/test_conjoin.rb +0 -50
- data/test/core/array/test_contains.rb +0 -14
- data/test/core/array/test_delete.rb +0 -42
- data/test/core/array/test_divide.rb +0 -14
- data/test/core/array/test_duplicates.rb +0 -29
- data/test/core/array/test_each_overlap.rb +0 -31
- data/test/core/array/test_entropy.rb +0 -23
- data/test/core/array/test_extract_options.rb +0 -28
- data/test/core/array/test_first.rb +0 -17
- data/test/core/array/test_index.rb +0 -20
- data/test/core/array/test_intersection.rb +0 -19
- data/test/core/array/test_last.rb +0 -17
- data/test/core/array/test_median.rb +0 -27
- data/test/core/array/test_merge.rb +0 -27
- data/test/core/array/test_missing.rb +0 -12
- data/test/core/array/test_mode.rb +0 -17
- data/test/core/array/test_nonuniq.rb +0 -25
- data/test/core/array/test_not_empty.rb +0 -17
- data/test/core/array/test_occur.rb +0 -52
- data/test/core/array/test_occurrence.rb +0 -20
- data/test/core/array/test_only.rb +0 -17
- data/test/core/array/test_pad.rb +0 -40
- data/test/core/array/test_peek.rb +0 -28
- data/test/core/array/test_permutation.rb +0 -20
- data/test/core/array/test_poke.rb +0 -21
- data/test/core/array/test_probability.rb +0 -18
- data/test/core/array/test_product.rb +0 -64
- data/test/core/array/test_pull.rb +0 -15
- data/test/core/array/test_recurse.rb +0 -40
- data/test/core/array/test_recursively.rb +0 -33
- data/test/core/array/test_reject_values.rb +0 -17
- data/test/core/array/test_rotate.rb +0 -38
- data/test/core/array/test_select.rb +0 -16
- data/test/core/array/test_splice.rb +0 -21
- data/test/core/array/test_split.rb +0 -22
- data/test/core/array/test_squeeze.rb +0 -22
- data/test/core/array/test_step.rb +0 -28
- data/test/core/array/test_store.rb +0 -22
- data/test/core/array/test_traverse.rb +0 -26
- data/test/core/array/test_uniq_by.rb +0 -17
- data/test/core/array/test_unique_permutation.rb +0 -23
- data/test/core/binding/test_caller.rb +0 -69
- data/test/core/binding/test_defined.rb +0 -18
- data/test/core/binding/test_eval.rb +0 -15
- data/test/core/binding/test_local_variables.rb +0 -36
- data/test/core/binding/test_op.rb +0 -24
- data/test/core/binding/test_self.rb +0 -16
- data/test/core/class/test_descendents.rb +0 -19
- data/test/core/class/test_preallocate.rb +0 -32
- data/test/core/class/test_subclasses.rb +0 -20
- data/test/core/class/test_to_proc.rb +0 -16
- data/test/core/comparable/test_bound.rb +0 -32
- data/test/core/comparable/test_cap.rb +0 -36
- data/test/core/comparable/test_clip.rb +0 -31
- data/test/core/comparable/test_cmp.rb +0 -16
- data/test/core/comparable/test_op_get.rb +0 -61
- data/test/core/denumerable_tc.rb +0 -194
- data/test/core/dir/test_ascend.rb +0 -40
- data/test/core/dir/test_descend.rb +0 -24
- data/test/core/dir/test_each_child.rb +0 -22
- data/test/core/dir/test_multiglob.rb +0 -25
- data/test/core/dir/test_parent.rb +0 -14
- data/test/core/dir/test_recurse.rb +0 -26
- data/test/core/enumerable/test_accumulate.rb +0 -44
- data/test/core/enumerable/test_cluster_by.rb +0 -30
- data/test/core/enumerable/test_compact_map.rb +0 -32
- data/test/core/enumerable/test_count.rb +0 -32
- data/test/core/enumerable/test_defer.rb +0 -27
- data/test/core/enumerable/test_each_by.rb +0 -49
- data/test/core/enumerable/test_each_with_object.rb +0 -18
- data/test/core/enumerable/test_every.rb +0 -33
- data/test/core/enumerable/test_ewise.rb +0 -30
- data/test/core/enumerable/test_exclude.rb +0 -15
- data/test/core/enumerable/test_expand.rb +0 -15
- data/test/core/enumerable/test_filter.rb +0 -19
- data/test/core/enumerable/test_find_yield.rb +0 -96
- data/test/core/enumerable/test_frequency.rb +0 -15
- data/test/core/enumerable/test_graph.rb +0 -42
- data/test/core/enumerable/test_group_by.rb +0 -36
- data/test/core/enumerable/test_key_by.rb +0 -22
- data/test/core/enumerable/test_map_by.rb +0 -27
- data/test/core/enumerable/test_map_send.rb +0 -26
- data/test/core/enumerable/test_map_with_index.rb +0 -23
- data/test/core/enumerable/test_mash.rb +0 -17
- data/test/core/enumerable/test_modulate.rb +0 -17
- data/test/core/enumerable/test_none.rb +0 -29
- data/test/core/enumerable/test_occur.rb +0 -40
- data/test/core/enumerable/test_one.rb +0 -34
- data/test/core/enumerable/test_only.rb +0 -40
- data/test/core/enumerable/test_per.rb +0 -19
- data/test/core/enumerable/test_purge.rb +0 -22
- data/test/core/enumerable/test_recursively.rb +0 -33
- data/test/core/enumerable/test_squeeze.rb +0 -35
- data/test/core/enumerable/test_sum.rb +0 -40
- data/test/core/enumerable/test_take.rb +0 -15
- data/test/core/enumerable/test_uniq_by.rb +0 -25
- data/test/core/enumerable/test_visit.rb +0 -14
- data/test/core/enumerator/lazy/test_squeeze.rb +0 -33
- data/test/core/enumerator/test_fx.rb +0 -16
- data/test/core/enumerator/test_new.rb +0 -21
- data/test/core/enumerator_tc.rb +0 -40
- data/test/core/exception/test_detail.rb +0 -15
- data/test/core/exception/test_raised.rb +0 -15
- data/test/core/exception/test_suppress.rb +0 -16
- data/test/core/file/test_append.rb +0 -22
- data/test/core/file/test_create.rb +0 -17
- data/test/core/file/test_ext.rb +0 -31
- data/test/core/file/test_null.rb +0 -14
- data/test/core/file/test_read_binary.rb +0 -19
- data/test/core/file/test_read_list.rb +0 -16
- data/test/core/file/test_rewrite.rb +0 -35
- data/test/core/file/test_rootname.rb +0 -13
- data/test/core/file/test_sanitize.rb +0 -32
- data/test/core/file/test_split_all.rb +0 -14
- data/test/core/file/test_write.rb +0 -22
- data/test/core/file/test_writelines.rb +0 -21
- data/test/core/filetest/test_root.rb +0 -14
- data/test/core/functor_tc.rb +0 -41
- data/test/core/hash/test_alias.rb +0 -25
- data/test/core/hash/test_argumentize.rb +0 -23
- data/test/core/hash/test_at.rb +0 -16
- data/test/core/hash/test_autonew.rb +0 -22
- data/test/core/hash/test_collate.rb +0 -61
- data/test/core/hash/test_count.rb +0 -23
- data/test/core/hash/test_data.rb +0 -35
- data/test/core/hash/test_dearray_values.rb +0 -26
- data/test/core/hash/test_deep_merge.rb +0 -31
- data/test/core/hash/test_deep_rekey.rb +0 -131
- data/test/core/hash/test_delete_at.rb +0 -18
- data/test/core/hash/test_delete_unless.rb +0 -18
- data/test/core/hash/test_delete_values.rb +0 -30
- data/test/core/hash/test_diff.rb +0 -16
- data/test/core/hash/test_each_with_key.rb +0 -16
- data/test/core/hash/test_expect.rb +0 -24
- data/test/core/hash/test_fetch_nested.rb +0 -24
- data/test/core/hash/test_graph.rb +0 -40
- data/test/core/hash/test_insert.rb +0 -20
- data/test/core/hash/test_inverse.rb +0 -20
- data/test/core/hash/test_join.rb +0 -32
- data/test/core/hash/test_keys.rb +0 -41
- data/test/core/hash/test_new_with.rb +0 -17
- data/test/core/hash/test_op_add.rb +0 -17
- data/test/core/hash/test_op_and.rb +0 -31
- data/test/core/hash/test_op_mul.rb +0 -17
- data/test/core/hash/test_op_or.rb +0 -17
- data/test/core/hash/test_op_push.rb +0 -34
- data/test/core/hash/test_op_sub.rb +0 -28
- data/test/core/hash/test_recurse.rb +0 -39
- data/test/core/hash/test_recursively.rb +0 -71
- data/test/core/hash/test_rekey.rb +0 -119
- data/test/core/hash/test_replace_each.rb +0 -17
- data/test/core/hash/test_revalue.rb +0 -98
- data/test/core/hash/test_reverse_merge.rb +0 -39
- data/test/core/hash/test_select.rb +0 -44
- data/test/core/hash/test_slice.rb +0 -36
- data/test/core/hash/test_stringify_keys.rb +0 -26
- data/test/core/hash/test_swap.rb +0 -15
- data/test/core/hash/test_symbolize_keys.rb +0 -26
- data/test/core/hash/test_to_mod.rb +0 -24
- data/test/core/hash/test_to_proc.rb +0 -23
- data/test/core/hash/test_to_struct.rb +0 -22
- data/test/core/hash/test_traverse.rb +0 -29
- data/test/core/hash/test_update_each.rb +0 -16
- data/test/core/hash/test_update_keys.rb +0 -21
- data/test/core/hash/test_update_values.rb +0 -15
- data/test/core/hash/test_url_params.rb +0 -26
- data/test/core/hash/test_weave.rb +0 -18
- data/test/core/hash/test_zip.rb +0 -16
- data/test/core/indexable_tc.rb +0 -226
- data/test/core/integer/test_bitmask.rb +0 -73
- data/test/core/integer/test_even.rb +0 -24
- data/test/core/integer/test_factorial.rb +0 -30
- data/test/core/integer/test_multiple.rb +0 -16
- data/test/core/integer/test_odd.rb +0 -24
- data/test/core/integer/test_of.rb +0 -36
- data/test/core/integer/test_ordinal.rb +0 -27
- data/test/core/kernel/test_as.rb +0 -74
- data/test/core/kernel/test_ask.rb +0 -9
- data/test/core/kernel/test_assign.rb +0 -61
- data/test/core/kernel/test_assign_from.rb +0 -48
- data/test/core/kernel/test_attr_singleton.rb +0 -51
- data/test/core/kernel/test_blank.rb +0 -103
- data/test/core/kernel/test_callstack.rb +0 -21
- data/test/core/kernel/test_class.rb +0 -14
- data/test/core/kernel/test_complete.rb +0 -19
- data/test/core/kernel/test_constant.rb +0 -18
- data/test/core/kernel/test_d.rb +0 -10
- data/test/core/kernel/test_deep_clone.rb +0 -31
- data/test/core/kernel/test_deep_copy.rb +0 -15
- data/test/core/kernel/test_dir.rb +0 -24
- data/test/core/kernel/test_disable_warnings.rb +0 -38
- data/test/core/kernel/test_ergo.rb +0 -32
- data/test/core/kernel/test_extension.rb +0 -18
- data/test/core/kernel/test_get.rb +0 -54
- data/test/core/kernel/test_here.rb +0 -13
- data/test/core/kernel/test_hierarchical_send.rb +0 -48
- data/test/core/kernel/test_in.rb +0 -14
- data/test/core/kernel/test_instance_assign.rb +0 -19
- data/test/core/kernel/test_instance_class.rb +0 -15
- data/test/core/kernel/test_instance_extract.rb +0 -28
- data/test/core/kernel/test_instance_send.rb +0 -26
- data/test/core/kernel/test_maybe.rb +0 -13
- data/test/core/kernel/test_meta_alias.rb +0 -18
- data/test/core/kernel/test_meta_class.rb +0 -33
- data/test/core/kernel/test_meta_def.rb +0 -15
- data/test/core/kernel/test_meta_eval.rb +0 -18
- data/test/core/kernel/test_method.rb +0 -20
- data/test/core/kernel/test_not.rb +0 -51
- data/test/core/kernel/test_not_nil.rb +0 -25
- data/test/core/kernel/test_object_class.rb +0 -22
- data/test/core/kernel/test_object_hexid.rb +0 -20
- data/test/core/kernel/test_object_send.rb +0 -25
- data/test/core/kernel/test_presence.rb +0 -37
- data/test/core/kernel/test_qua_class.rb +0 -25
- data/test/core/kernel/test_require_all.rb +0 -11
- data/test/core/kernel/test_require_relative.rb +0 -12
- data/test/core/kernel/test_respond.rb +0 -38
- data/test/core/kernel/test_returning.rb +0 -17
- data/test/core/kernel/test_silence.rb +0 -24
- data/test/core/kernel/test_singleton_class.rb +0 -15
- data/test/core/kernel/test_super_method.rb +0 -23
- data/test/core/kernel/test_tap.rb +0 -38
- data/test/core/kernel/test_temporarily.rb +0 -25
- data/test/core/kernel/test_true.rb +0 -31
- data/test/core/kernel/test_try.rb +0 -35
- data/test/core/kernel/test_val.rb +0 -30
- data/test/core/kernel/test_with.rb +0 -18
- data/test/core/kernel/test_writers.rb +0 -53
- data/test/core/matchdata/test_match.rb +0 -14
- data/test/core/matchdata/test_matchset.rb +0 -29
- data/test/core/method/test_composition.rb +0 -42
- data/test/core/module/test_abstract.rb +0 -24
- data/test/core/module/test_alias_accessor.rb +0 -27
- data/test/core/module/test_alias_method_chain.rb +0 -34
- data/test/core/module/test_alias_module_function.rb +0 -24
- data/test/core/module/test_all_instance_methods.rb +0 -27
- data/test/core/module/test_ancestor.rb +0 -16
- data/test/core/module/test_anonymous.rb +0 -18
- data/test/core/module/test_attr_setter.rb +0 -28
- data/test/core/module/test_basename.rb +0 -14
- data/test/core/module/test_can.rb +0 -22
- data/test/core/module/test_class.rb +0 -22
- data/test/core/module/test_class_def.rb +0 -22
- data/test/core/module/test_class_extend.rb +0 -73
- data/test/core/module/test_class_inheritor.rb +0 -135
- data/test/core/module/test_copy_inheritor.rb +0 -35
- data/test/core/module/test_enclosure.rb +0 -24
- data/test/core/module/test_instance_function.rb +0 -30
- data/test/core/module/test_instance_method.rb +0 -20
- data/test/core/module/test_instance_method_defined.rb +0 -38
- data/test/core/module/test_integrate.rb +0 -28
- data/test/core/module/test_is.rb +0 -50
- data/test/core/module/test_memoize.rb +0 -33
- data/test/core/module/test_method_clash.rb +0 -59
- data/test/core/module/test_method_space.rb +0 -72
- data/test/core/module/test_methodize.rb +0 -26
- data/test/core/module/test_modname.rb +0 -13
- data/test/core/module/test_module_def.rb +0 -22
- data/test/core/module/test_module_load.rb +0 -23
- data/test/core/module/test_nodef.rb +0 -19
- data/test/core/module/test_op.rb +0 -56
- data/test/core/module/test_pathize.rb +0 -25
- data/test/core/module/test_preextend.rb +0 -26
- data/test/core/module/test_redefine_method.rb +0 -30
- data/test/core/module/test_redirect_method.rb +0 -32
- data/test/core/module/test_remove.rb +0 -18
- data/test/core/module/test_rename_method.rb +0 -34
- data/test/core/module/test_revise.rb +0 -61
- data/test/core/module/test_set.rb +0 -30
- data/test/core/module/test_spacename.rb +0 -15
- data/test/core/module/test_to_obj.rb +0 -20
- data/test/core/module/test_wrap_method.rb +0 -32
- data/test/core/nilclass/test_to_f.rb +0 -13
- data/test/core/numeric/test_approx.rb +0 -26
- data/test/core/numeric/test_distance.rb +0 -16
- data/test/core/numeric/test_length.rb +0 -16
- data/test/core/numeric/test_round.rb +0 -76
- data/test/core/numeric/test_spacing.rb +0 -17
- data/test/core/object/test_dup.rb +0 -115
- data/test/core/object/test_object_state.rb +0 -75
- data/test/core/object/test_replace.rb +0 -69
- data/test/core/object/test_try_dup.rb +0 -59
- data/test/core/proc/test_bind.rb +0 -29
- data/test/core/proc/test_bind_to.rb +0 -17
- data/test/core/proc/test_compose.rb +0 -27
- data/test/core/proc/test_curry.rb +0 -38
- data/test/core/proc/test_partial.rb +0 -27
- data/test/core/proc/test_to_method.rb +0 -43
- data/test/core/proc/test_update.rb +0 -15
- data/test/core/range/test_combine.rb +0 -32
- data/test/core/range/test_op_add.rb +0 -24
- data/test/core/range/test_op_sub.rb +0 -34
- data/test/core/range/test_overlap.rb +0 -15
- data/test/core/range/test_to_r.rb +0 -20
- data/test/core/range/test_umbrella.rb +0 -32
- data/test/core/range/test_within.rb +0 -25
- data/test/core/regexp/test_arity.rb +0 -30
- data/test/core/regexp/test_multiline.rb +0 -19
- data/test/core/regexp/test_op_add.rb +0 -15
- data/test/core/regexp/test_op_or.rb +0 -16
- data/test/core/regexp/test_to_re.rb +0 -24
- data/test/core/string/test_align.rb +0 -32
- data/test/core/string/test_ascii_only.rb +0 -30
- data/test/core/string/test_bracket.rb +0 -37
- data/test/core/string/test_bytes.rb +0 -13
- data/test/core/string/test_camelcase.rb +0 -59
- data/test/core/string/test_capitalized.rb +0 -36
- data/test/core/string/test_characters.rb +0 -13
- data/test/core/string/test_cleanlines.rb +0 -12
- data/test/core/string/test_cleave.rb +0 -27
- data/test/core/string/test_cmp.rb +0 -18
- data/test/core/string/test_compress_lines.rb +0 -18
- data/test/core/string/test_divide.rb +0 -17
- data/test/core/string/test_each_char.rb +0 -17
- data/test/core/string/test_each_word.rb +0 -17
- data/test/core/string/test_edit_distance.rb +0 -20
- data/test/core/string/test_end_with.rb +0 -24
- data/test/core/string/test_exclude.rb +0 -23
- data/test/core/string/test_expand_tabs.rb +0 -83
- data/test/core/string/test_file.rb +0 -15
- data/test/core/string/test_fold.rb +0 -21
- data/test/core/string/test_indent.rb +0 -90
- data/test/core/string/test_index_all.rb +0 -18
- data/test/core/string/test_interpolate.rb +0 -16
- data/test/core/string/test_lchomp.rb +0 -25
- data/test/core/string/test_line_wrap.rb +0 -15
- data/test/core/string/test_lines.rb +0 -15
- data/test/core/string/test_lowercase.rb +0 -18
- data/test/core/string/test_margin.rb +0 -16
- data/test/core/string/test_methodize.rb +0 -28
- data/test/core/string/test_modulize.rb +0 -28
- data/test/core/string/test_mscan.rb +0 -18
- data/test/core/string/test_natcmp.rb +0 -17
- data/test/core/string/test_nchar.rb +0 -17
- data/test/core/string/test_newlines.rb +0 -14
- data/test/core/string/test_number.rb +0 -44
- data/test/core/string/test_op_div.rb +0 -15
- data/test/core/string/test_op_sub.rb +0 -15
- data/test/core/string/test_pathize.rb +0 -31
- data/test/core/string/test_quote.rb +0 -41
- data/test/core/string/test_range.rb +0 -35
- data/test/core/string/test_remove.rb +0 -36
- data/test/core/string/test_rewrite.rb +0 -17
- data/test/core/string/test_rotate.rb +0 -31
- data/test/core/string/test_shatter.rb +0 -17
- data/test/core/string/test_similarity.rb +0 -14
- data/test/core/string/test_snakecase.rb +0 -22
- data/test/core/string/test_splice.rb +0 -37
- data/test/core/string/test_squish.rb +0 -31
- data/test/core/string/test_start_with.rb +0 -24
- data/test/core/string/test_store.rb +0 -16
- data/test/core/string/test_subtract.rb +0 -16
- data/test/core/string/test_tab.rb +0 -16
- data/test/core/string/test_titlecase.rb +0 -16
- data/test/core/string/test_to_re.rb +0 -35
- data/test/core/string/test_trim.rb +0 -116
- data/test/core/string/test_unbracket.rb +0 -38
- data/test/core/string/test_underscore.rb +0 -21
- data/test/core/string/test_unfold.rb +0 -17
- data/test/core/string/test_unindent.rb +0 -105
- data/test/core/string/test_unquote.rb +0 -13
- data/test/core/string/test_uppercase.rb +0 -22
- data/test/core/string/test_variablize.rb +0 -15
- data/test/core/string/test_word_wrap.rb +0 -80
- data/test/core/string/test_words.rb +0 -24
- data/test/core/string/test_xor.rb +0 -16
- data/test/core/symbol/test_as_s.rb +0 -15
- data/test/core/symbol/test_bang.rb +0 -15
- data/test/core/symbol/test_chomp.rb +0 -22
- data/test/core/symbol/test_generate.rb +0 -20
- data/test/core/symbol/test_not.rb +0 -19
- data/test/core/symbol/test_op_div.rb +0 -15
- data/test/core/symbol/test_plain.rb +0 -19
- data/test/core/symbol/test_query.rb +0 -19
- data/test/core/symbol/test_setter.rb +0 -17
- data/test/core/symbol/test_succ.rb +0 -16
- data/test/core/symbol/test_thrown.rb +0 -22
- data/test/core/symbol/test_to_proc.rb +0 -35
- data/test/core/symbol/test_variablize.rb +0 -14
- data/test/core/time/test_ago.rb +0 -18
- data/test/core/time/test_change.rb +0 -17
- data/test/core/time/test_dst_adjustment.rb +0 -19
- data/test/core/time/test_elapse.rb +0 -15
- data/test/core/time/test_future.rb +0 -32
- data/test/core/time/test_hence.rb +0 -18
- data/test/core/time/test_in.rb +0 -18
- data/test/core/time/test_less.rb +0 -139
- data/test/core/time/test_past.rb +0 -32
- data/test/core/time/test_round_to.rb +0 -34
- data/test/core/time/test_set.rb +0 -43
- data/test/core/time/test_shift.rb +0 -135
- data/test/core/time/test_stamp.rb +0 -42
- data/test/core/time/test_to_time.rb +0 -15
- data/test/core/time/test_trunc.rb +0 -34
- data/test/core/to_hash_tc.rb +0 -210
- data/test/core/unboundmethod/test_arguments.rb +0 -25
- data/test/core/unboundmethod/test_name.rb +0 -19
- data/test/standard/binding/test_block_exec.rb +0 -21
- data/test/standard/math/test_abs.rb +0 -13
- data/test/standard/math/test_acot.rb +0 -23
- data/test/standard/math/test_acoth.rb +0 -22
- data/test/standard/math/test_beta.rb +0 -19
- data/test/standard/math/test_ceil.rb +0 -22
- data/test/standard/math/test_cosec.rb +0 -19
- data/test/standard/math/test_cosech.rb +0 -19
- data/test/standard/math/test_cot.rb +0 -13
- data/test/standard/math/test_coth.rb +0 -13
- data/test/standard/math/test_distance.rb +0 -16
- data/test/standard/math/test_exp10.rb +0 -14
- data/test/standard/math/test_exp2.rb +0 -14
- data/test/standard/math/test_factorial.rb +0 -13
- data/test/standard/math/test_floor.rb +0 -23
- data/test/standard/math/test_gcd.rb +0 -18
- data/test/standard/math/test_lcm.rb +0 -13
- data/test/standard/math/test_median.rb +0 -17
- data/test/standard/math/test_percentile.rb +0 -13
- data/test/standard/math/test_pow.rb +0 -30
- data/test/standard/math/test_root.rb +0 -15
- data/test/standard/math/test_sec.rb +0 -19
- data/test/standard/math/test_sech.rb +0 -19
- data/test/standard/math/test_sign.rb +0 -20
- data/test/standard/math/test_sinc.rb +0 -15
- data/test/standard/math/test_srq.rb +0 -20
- data/test/standard/pathname/test_chdir.rb +0 -16
- data/test/standard/pathname/test_readline.rb +0 -23
- data/test/standard/test_argvector.rb +0 -64
- data/test/standard/test_cloneable.rb +0 -60
- data/test/standard/test_date.rb +0 -82
- data/test/standard/test_enumargs.rb +0 -89
- data/test/standard/test_equitable.rb +0 -46
- data/test/standard/test_instantiable.rb +0 -40
- data/test/standard/test_math.rb +0 -3
- data/test/standard/test_memoizable.rb +0 -42
- data/test/standard/test_multipliers.rb +0 -141
- data/test/standard/test_ostruct.rb +0 -191
- data/test/standard/test_random.rb +0 -241
- data/test/standard/test_shellwords.rb +0 -74
- data/test/standard/test_thread.rb +0 -24
- data/test/standard/test_timer.rb +0 -62
- data/test/standard/test_tuple.rb +0 -68
- data/test/standard/test_uri.rb +0 -50
|
@@ -1,42 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
# The `arrange` method produces appropriate ranges from the objects in the array.
|
|
4
|
-
#
|
|
5
|
-
# Examples
|
|
6
|
-
#
|
|
7
|
-
# [1,2,3,6,7,8].arrange #=> [1..3, 6..8]
|
|
8
|
-
#
|
|
9
|
-
# [10..15, 16..20, 21, 22].arrange #=> [10..22]
|
|
10
|
-
#
|
|
11
|
-
# Assumes inclusive ranges (ie. 1..4) and range.first <= range.last.
|
|
12
|
-
#
|
|
13
|
-
# Works with integers, dates and strings. However, all the objects in the array must
|
|
14
|
-
# be of the same class.
|
|
15
|
-
#
|
|
16
|
-
# CREDIT: monocle
|
|
17
|
-
|
|
18
|
-
def arrange
|
|
19
|
-
array = uniq.sort_by { |e| Range === e ? e.first : e }
|
|
20
|
-
array.inject([]) do |c, value|
|
|
21
|
-
unless c.empty?
|
|
22
|
-
last = c.last
|
|
23
|
-
last_value = (Range === last ? last.last : last)
|
|
24
|
-
current_value = (Range === value ? value.first : value)
|
|
25
|
-
if (last_value.succ <=> current_value) == -1
|
|
26
|
-
c << value
|
|
27
|
-
else
|
|
28
|
-
first = (Range === last ? last.first : last)
|
|
29
|
-
second = [Range === last ? last.last : last, Range === value ? value.last : value].max
|
|
30
|
-
c[-1] = [first..second]
|
|
31
|
-
c.flatten!
|
|
32
|
-
end
|
|
33
|
-
else
|
|
34
|
-
c << value
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
alias rangify arrange
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
1
|
+
require 'facets/array/to_ranges'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
|
|
3
|
+
# Calculate the average of an array of numbers
|
|
4
|
+
#
|
|
5
|
+
# Examples
|
|
6
|
+
#
|
|
7
|
+
# [].average #=> nil
|
|
8
|
+
# [1, 2, 3].average #=> 2
|
|
9
|
+
# [3, 12, 57, 85, 15, 89, 33, 7, 22, 54].average #=> 37.7
|
|
10
|
+
#
|
|
11
|
+
def average
|
|
12
|
+
return nil if empty?
|
|
13
|
+
self.reduce(:+)/length.to_f
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -19,7 +19,7 @@ class Array
|
|
|
19
19
|
self[(index(value).to_i - 1) % length]
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
# Returns the value
|
|
22
|
+
# Returns the value next to the given value. The value next to the last
|
|
23
23
|
# is the first. Returns nil if the given value is not in the array.
|
|
24
24
|
#
|
|
25
25
|
# Examples
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
# Deletes first item from +self+ that is equal to +obj+.
|
|
3
|
+
#
|
|
4
|
+
# Returns the deleted item, or +nil+ if no matching item is found.
|
|
5
|
+
#
|
|
6
|
+
# If the optional code block is given, the result of the block is returned if
|
|
7
|
+
# the item is not found.
|
|
8
|
+
#
|
|
9
|
+
# a = [ "a", "b", "b", "b", "c" ]
|
|
10
|
+
# a.delete_first("b") #=> "b"
|
|
11
|
+
# a #=> ["a", "c"]
|
|
12
|
+
# a.delete("z") #=> nil
|
|
13
|
+
# a.delete("z") {"not found"} #=> "not found"
|
|
14
|
+
def delete_first(el)
|
|
15
|
+
i = index(el)
|
|
16
|
+
if i
|
|
17
|
+
delete_at(i)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'facets/array/delete_values'
|
|
@@ -5,10 +5,17 @@ class Array
|
|
|
5
5
|
# ['a1','b1','a2','b2'].divide(/^a/)
|
|
6
6
|
# #=> [['a1','b1'],['a2','b2']]
|
|
7
7
|
#
|
|
8
|
+
# ['a1','b1','a2','b2'].divide(/^b/)
|
|
9
|
+
# #=> [['a1',['b1','a2'],[]'b2']]
|
|
10
|
+
#
|
|
11
|
+
# ['a1','b1','a2','b2'].divide(/^c/)
|
|
12
|
+
# #=> [['a1','b1','a2','b2']]
|
|
13
|
+
#
|
|
8
14
|
# CREDIT: Trans
|
|
9
15
|
|
|
10
16
|
def divide(pattern)
|
|
11
17
|
memo = []
|
|
18
|
+
memo.push [] unless pattern === first
|
|
12
19
|
each do |obj|
|
|
13
20
|
memo.push [] if pattern === obj
|
|
14
21
|
memo.last << obj
|
|
@@ -8,6 +8,8 @@ class Array
|
|
|
8
8
|
#
|
|
9
9
|
# [1,1,2,3].duplicates #=> [1]
|
|
10
10
|
#
|
|
11
|
+
# [1,1,2,3,2,4,5,4,2].duplicates(3) #=> [2]
|
|
12
|
+
#
|
|
11
13
|
# CREDIT: Rebort Dober (current implementation)
|
|
12
14
|
# CREDIT: Thibaut Barrère
|
|
13
15
|
|
|
@@ -19,4 +21,17 @@ class Array
|
|
|
19
21
|
h.delete_if{|_,v| v < min}.keys
|
|
20
22
|
end
|
|
21
23
|
|
|
24
|
+
# In-place version of #duplicates. Replaces the array with
|
|
25
|
+
# only its duplicate elements.
|
|
26
|
+
#
|
|
27
|
+
# Examples:
|
|
28
|
+
#
|
|
29
|
+
# a = [1,1,2,3,2]
|
|
30
|
+
# a.duplicates! #=> [1,2]
|
|
31
|
+
# a #=> [1,2]
|
|
32
|
+
#
|
|
33
|
+
def duplicates!(min=2)
|
|
34
|
+
replace(duplicates(min))
|
|
35
|
+
end
|
|
36
|
+
|
|
22
37
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'facets/array/indexable'
|
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
class Array
|
|
2
2
|
|
|
3
|
-
# Returns
|
|
3
|
+
# Returns elements from `index` until the end.
|
|
4
4
|
#
|
|
5
|
-
# %w{W o r l d}.from(3) #=>
|
|
5
|
+
# %w{W o r l d}.from(3) #=> ["l", "d"]
|
|
6
|
+
# %w{W o r l d}.from(9) #=> []
|
|
6
7
|
#
|
|
7
|
-
def from(
|
|
8
|
-
return
|
|
9
|
-
self[
|
|
8
|
+
def from(index)
|
|
9
|
+
return [] if index >= size
|
|
10
|
+
self[index..-1]
|
|
10
11
|
end unless method_defined?(:from)
|
|
11
12
|
|
|
12
13
|
# Fetch values from a start index thru an end index.
|
|
13
14
|
#
|
|
14
|
-
# [1,2,3,4,5].thru(0,2) #=> [1,2,3]
|
|
15
|
-
# [1,2,3,4,5].thru(2,4) #=> [3,4,5]
|
|
16
|
-
#
|
|
17
15
|
# [1,2,3,4,5].thru(2) #=> [1,2,3]
|
|
18
16
|
# [1,2,3,4,5].thru(4) #=> [1,2,3,4,5]
|
|
19
17
|
#
|
|
18
|
+
# [1,2,3,4,5].thru(0,2) #=> [1,2,3]
|
|
19
|
+
# [1,2,3,4,5].thru(2,4) #=> [3,4,5]
|
|
20
|
+
#
|
|
20
21
|
def thru(from, to=nil)
|
|
21
22
|
from, to = 0, from unless to
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
i = from
|
|
25
|
-
while i <= to
|
|
26
|
-
a << self[i]
|
|
27
|
-
i += 1
|
|
28
|
-
end
|
|
29
|
-
a
|
|
23
|
+
return [] if from >= size
|
|
24
|
+
self[from..to]
|
|
30
25
|
end unless method_defined?(:thru)
|
|
31
26
|
|
|
32
27
|
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
# Returns an array of _indexes_ of all objects in receiver such that the object is == to obj.
|
|
3
|
+
#
|
|
4
|
+
# If a block is given instead of an argument, returns the _indexes_ of all objects for which the
|
|
5
|
+
# block returns true.
|
|
6
|
+
#
|
|
7
|
+
# If neither a block nor argument is given, an Enumerator for _all_ indexes (each_index) is returned.
|
|
8
|
+
#
|
|
9
|
+
# Returns [] if no match is found.
|
|
10
|
+
#
|
|
11
|
+
# a = [ "a", "b", "c" ]
|
|
12
|
+
# a.indexes("b").to_a #=> [1]
|
|
13
|
+
# a.indexes("z").to_a #=> []
|
|
14
|
+
# a.indexes { |x| x == "b" }.to_a #=> [1]
|
|
15
|
+
#
|
|
16
|
+
# Like Array#index/rindex and Enumerable#find_index but returns _all_ indexes instead of just the
|
|
17
|
+
# first/last.
|
|
18
|
+
#
|
|
19
|
+
# See also: proposal to add Array#indexes to Ruby language: https://bugs.ruby-lang.org/issues/6596
|
|
20
|
+
#
|
|
21
|
+
# @author Tyler Rick
|
|
22
|
+
def indexes(*args)
|
|
23
|
+
case args.length
|
|
24
|
+
when 0
|
|
25
|
+
if block_given?
|
|
26
|
+
each_index.select {|i| yield(self[i]) }
|
|
27
|
+
else
|
|
28
|
+
each_index
|
|
29
|
+
end
|
|
30
|
+
when 1
|
|
31
|
+
other = args.first
|
|
32
|
+
each_index.select {|i| self[i] == other }
|
|
33
|
+
else
|
|
34
|
+
raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0..1)"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
alias_method :index_all, :indexes
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module Enumerable
|
|
41
|
+
# Returns an enumerator of _indexes_ of all objects in receiver such that the object is == to obj.
|
|
42
|
+
#
|
|
43
|
+
# If a block is given instead of an argument, returns the _indexes_ of all objects for which the
|
|
44
|
+
# block returns true.
|
|
45
|
+
#
|
|
46
|
+
# If neither a block nor argument is given, an Enumerator for _all_ indexes is returned.
|
|
47
|
+
#
|
|
48
|
+
# Returns [] if no match is found.
|
|
49
|
+
#
|
|
50
|
+
# a = ("a".."c")
|
|
51
|
+
# a.indexes("b").to_a #=> [1]
|
|
52
|
+
# a.indexes("z").to_a #=> []
|
|
53
|
+
# a.indexes { |x| x == "b" }.to_a #=> [1]
|
|
54
|
+
#
|
|
55
|
+
# Like Array#index/rindex and Enumerable#find_index but returns _all_ indexes instead of just the
|
|
56
|
+
# first/last.
|
|
57
|
+
#
|
|
58
|
+
# See also: proposal to add Array#indexes to Ruby language: https://bugs.ruby-lang.org/issues/6596
|
|
59
|
+
#
|
|
60
|
+
# @author Tyler Rick
|
|
61
|
+
#
|
|
62
|
+
def indexes(*args)
|
|
63
|
+
# Enumerable doesn't have each_index like Array has, so this uses each_with_index instead.
|
|
64
|
+
case args.length
|
|
65
|
+
when 0
|
|
66
|
+
if block_given?
|
|
67
|
+
each_with_index.select {|el, i| yield(el) }.map {|el, i| i }
|
|
68
|
+
else
|
|
69
|
+
each_with_index. map {|el, i| i }.to_enum
|
|
70
|
+
end
|
|
71
|
+
when 1
|
|
72
|
+
other = args.first
|
|
73
|
+
each_with_index. select {|el, i| el == other }.map {|el, i| i }
|
|
74
|
+
else
|
|
75
|
+
raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0..1)"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
alias_method :index_all, :indexes
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Enumerator::Lazy
|
|
82
|
+
# Returns an enumerator of _indexes_ of all object in receiver such that the object is == to obj.
|
|
83
|
+
#
|
|
84
|
+
# If a block is given instead of an argument, returns the _indexes_ of all objects for which the
|
|
85
|
+
# block returns true.
|
|
86
|
+
#
|
|
87
|
+
# If neither a block nor argument is given, an Enumerator for _all_ indexes is returned.
|
|
88
|
+
#
|
|
89
|
+
# enum = (42 .. Float::INFINITY).lazy.indexes
|
|
90
|
+
# #=> #<Enumerator::Lazy: ...>
|
|
91
|
+
# enum.next #=> 0
|
|
92
|
+
# enum.next #=> 1
|
|
93
|
+
# enum.first(5) #=> [0, 1, 2, 3, 4]
|
|
94
|
+
#
|
|
95
|
+
# @author Tyler Rick
|
|
96
|
+
#
|
|
97
|
+
def indexes(*args)
|
|
98
|
+
case args.length
|
|
99
|
+
when 0
|
|
100
|
+
if block_given?
|
|
101
|
+
each_with_index.lazy.select {|el, i| yield(el) }.map {|el, i| i }
|
|
102
|
+
else
|
|
103
|
+
each_with_index.lazy. map {|el, i| i }.to_enum
|
|
104
|
+
end
|
|
105
|
+
when 1
|
|
106
|
+
other = args.first
|
|
107
|
+
each_with_index.lazy. select {|el, i| el == other }.map {|el, i| i }
|
|
108
|
+
else
|
|
109
|
+
raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0..1)"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
alias_method :index_all, :indexes
|
|
113
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'facets/array/indexable'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class Array
|
|
2
2
|
|
|
3
|
-
# In Statistics mode is the value that occurs most frequently
|
|
3
|
+
# In Statistics. mode is the value that occurs most frequently
|
|
4
4
|
# in a given set of data. This method returns an array in case
|
|
5
|
-
#
|
|
5
|
+
# there is a tie.
|
|
6
6
|
#
|
|
7
7
|
# [:a, :b, :c, :b, :d].mode #=> [:b]
|
|
8
8
|
# [:a, :b, :c, :b, :a].mode #=> [:a, :b]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'facets/array/duplicates'
|
|
2
|
+
|
|
1
3
|
class Array
|
|
2
4
|
|
|
3
5
|
# Returns a list of non-unique elements.
|
|
@@ -9,19 +11,15 @@ class Array
|
|
|
9
11
|
# CREDIT: Martin DeMello
|
|
10
12
|
|
|
11
13
|
def nonuniq
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
each {|i|
|
|
15
|
-
h2[i] = true if h1[i]
|
|
16
|
-
h1[i] = true
|
|
17
|
-
}
|
|
18
|
-
h2.keys
|
|
14
|
+
warn "Array#nonuniq is deprecated. Use Array#duplicates instead.", uplevel: 1
|
|
15
|
+
duplicates
|
|
19
16
|
end
|
|
20
17
|
|
|
21
18
|
# Same as `#nonuniq` but acts in place.
|
|
22
19
|
|
|
23
20
|
def nonuniq!
|
|
24
|
-
|
|
21
|
+
warn "Array#nonuniq! is deprecated. Use Array#duplicates instead.", uplevel: 1
|
|
22
|
+
self.replace(duplicates)
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
end
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
class Array
|
|
2
2
|
|
|
3
|
-
# Create a
|
|
3
|
+
# Create a hash of each uniq element of the array
|
|
4
|
+
# and how many time each appears.
|
|
4
5
|
#
|
|
5
6
|
# Examples
|
|
6
7
|
#
|
|
7
8
|
# [:a,:a,:b,:c,:c,:c].occurrence
|
|
8
|
-
# #=> { :a => 2, :b => 1, :c => 3 }
|
|
9
|
+
# #=> { :a => 2, :b => 1, :c => 3 }
|
|
9
10
|
#
|
|
10
|
-
# [2,2,3,4,4,4].
|
|
11
|
+
# [2,2,3,4,4,4].occurrence{|i| i % 2}
|
|
11
12
|
# #=> { 0 => 5, 1 => 1 }
|
|
12
13
|
#
|
|
14
|
+
# Without a block, this is equivalent to Ruby's #tally.
|
|
15
|
+
# With a block, the block transforms the key before counting,
|
|
16
|
+
# which #tally does not support.
|
|
17
|
+
#
|
|
13
18
|
def occurrence
|
|
14
19
|
h = Hash.new(0)
|
|
15
20
|
if block_given?
|
|
@@ -25,4 +30,3 @@ class Array
|
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
end
|
|
28
|
-
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Array
|
|
2
2
|
|
|
3
3
|
# Generates a hash mapping each unique element in the array to the
|
|
4
|
-
# relative frequency, i.e. the
|
|
4
|
+
# relative frequency, i.e. the probability, of it appearance.
|
|
5
5
|
#
|
|
6
6
|
# [:a, :b, :c, :c].probability #=> {:a=> 0.25, :b=>0.25, :c=>0.5}
|
|
7
7
|
#
|
|
@@ -6,11 +6,11 @@ class Array
|
|
|
6
6
|
# Apply a method to array, and recursively apply that method
|
|
7
7
|
# to each sub-array or given +types+.
|
|
8
8
|
#
|
|
9
|
-
# By default the sub-types are passed
|
|
9
|
+
# By default the sub-types are passed through unaffected. Passing
|
|
10
10
|
# a block to #recursively can be used to change this.
|
|
11
11
|
#
|
|
12
12
|
# types - List of class types to recurse. [Array<Class>]
|
|
13
|
-
# block - Optional filter procedure to apply on each recursion.
|
|
13
|
+
# block - Optional filter procedure to apply on each recursion.
|
|
14
14
|
#
|
|
15
15
|
# Examples
|
|
16
16
|
#
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
# Returns a new array that is a copy of the original array, removing the first occurrence of any
|
|
3
|
+
# item that also appears in +other_ary+. The order is preserved from the original array.
|
|
4
|
+
#
|
|
5
|
+
# If there are multiple occurrences of an item in +other_ary+, this removes that many occurrences
|
|
6
|
+
# from self.
|
|
7
|
+
#
|
|
8
|
+
# This is similar to `Array#-` and `Array#difference`, except that instead of removing _all_
|
|
9
|
+
# matches, it only removes as many occurrences as there are in the +other_ary+:
|
|
10
|
+
#
|
|
11
|
+
# > [1, 1, 2].remove [1]
|
|
12
|
+
# => [1, 2]
|
|
13
|
+
#
|
|
14
|
+
# > [1, 1, 2].remove [1, 1, 1]
|
|
15
|
+
# => [2]
|
|
16
|
+
#
|
|
17
|
+
# > [1, 1, 2] - [1]
|
|
18
|
+
# => [2]
|
|
19
|
+
#
|
|
20
|
+
# > [1, 1, 2].difference [1]
|
|
21
|
+
# => [2]
|
|
22
|
+
#
|
|
23
|
+
def remove(other_ary)
|
|
24
|
+
dup.remove!(other_ary)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# For each element of `other_ary`, deletes the _first_ element from self that is equal to that element
|
|
28
|
+
# (using `delete_at`, not `delete`).
|
|
29
|
+
#
|
|
30
|
+
# This is the in-place version of remove.
|
|
31
|
+
#
|
|
32
|
+
def remove!(other_ary)
|
|
33
|
+
other_ary.each do |el|
|
|
34
|
+
i = index(el)
|
|
35
|
+
delete_at(i) if i
|
|
36
|
+
end
|
|
37
|
+
self
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
# Public: Split an array in two using a predicate
|
|
3
|
+
#
|
|
4
|
+
# Yields each element of the array.
|
|
5
|
+
#
|
|
6
|
+
# Examples
|
|
7
|
+
#
|
|
8
|
+
# %w(The quick brown fox).span { |word| word.length < 4 }
|
|
9
|
+
# #=> [['The'], ['quick', 'brown', 'fox']]
|
|
10
|
+
#
|
|
11
|
+
# [1, 1, 2, 3, 5, 8, 13, 21, 34].span(&:odd?)
|
|
12
|
+
# #=> [[1, 1], [2, 3, 5, 8, 13, 21, 34]]
|
|
13
|
+
#
|
|
14
|
+
# Returns a 2-tuple of arrays, the first element being the longest prefix for
|
|
15
|
+
# which the block evaluates to true, the second element being the rest of the
|
|
16
|
+
# array.
|
|
17
|
+
#
|
|
18
|
+
# TODO: This is based on Haskell's `span`, but the name is not intuitive
|
|
19
|
+
# for Ruby. Consider a more descriptive name (e.g. `split_while`).
|
|
20
|
+
# Also consider adding the inverse (Haskell's `break`), which splits
|
|
21
|
+
# where the predicate first becomes true.
|
|
22
|
+
def span
|
|
23
|
+
# This implementation is another way of saying
|
|
24
|
+
# `[take_while(&:block), drop_while(&:block)]`
|
|
25
|
+
index = find_index { |e| !yield e }
|
|
26
|
+
return [dup, []] if index.nil?
|
|
27
|
+
[take(index), drop(index)]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
|
|
3
|
+
# Split on matching pattern. Breaks the array into [before, middle, after]
|
|
4
|
+
# segments. Uses Array#index to find the middle element.
|
|
5
|
+
#
|
|
6
|
+
# Examples
|
|
7
|
+
#
|
|
8
|
+
# ['a1','a2','b1','a3','b2','a4'].split('b1')
|
|
9
|
+
# #=> [['a1','a2'],b1,['a3','b2','a4']]
|
|
10
|
+
#
|
|
11
|
+
# ['a1','a2','b1','a3','b2','a4'].split('foo')
|
|
12
|
+
# #=> [[],nil,[]]
|
|
13
|
+
#
|
|
14
|
+
# Returns list of split-up arrays. [Tuple<Array,Object,Array>]
|
|
15
|
+
|
|
16
|
+
def split_at(*args, &block)
|
|
17
|
+
if middle = index(*args, &block)
|
|
18
|
+
[self[0...middle], self[middle], self[middle+1..-1]]
|
|
19
|
+
else
|
|
20
|
+
[[], nil, []]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'facets/array/variance'
|
|
2
|
+
|
|
3
|
+
class Array
|
|
4
|
+
|
|
5
|
+
# Calculate the standard_deviation of an array of numbers
|
|
6
|
+
#
|
|
7
|
+
# Examples
|
|
8
|
+
#
|
|
9
|
+
# [].standard_deviation #=> nil
|
|
10
|
+
# [1, 2, 3].standard_deviation #=> 0.816496580927726
|
|
11
|
+
# [96, 35, 72, 30, 75, 33, 68, 13, 49, 71].standard_deviation #=> 24.69331893448104
|
|
12
|
+
# [36, -67, -17, 85, -46, -64, -23, -13, 89, -47].standard_deviation #=> 54.67183918618432
|
|
13
|
+
# [60.7829, 31.2622, 20.626, 78.8907, 61.5328].standard_deviation #=> 21.428815505053002
|
|
14
|
+
#
|
|
15
|
+
def stddev
|
|
16
|
+
return nil if empty?
|
|
17
|
+
Math.sqrt(variance)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
alias sd stddev
|
|
21
|
+
|
|
22
|
+
def standard_deviation
|
|
23
|
+
warn "Array#standard_deviation is deprecated. Use Array#stddev or Array#sd instead.", uplevel: 1
|
|
24
|
+
stddev
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
@@ -2,30 +2,28 @@ class Array
|
|
|
2
2
|
|
|
3
3
|
# Iterate over every nth element of an array.
|
|
4
4
|
#
|
|
5
|
+
# An optional offset can be given to start from a
|
|
6
|
+
# specific index (default is 0).
|
|
7
|
+
#
|
|
8
|
+
# [:a, :b, :c, :d, :e, :f].step(2).to_a #=> [:a, :c, :e]
|
|
9
|
+
# [:a, :b, :c, :d, :e, :f].step(2, 1).to_a #=> [:b, :d, :f]
|
|
10
|
+
# [:a, :b, :c, :d, :e, :f].step(3).to_a #=> [:a, :d]
|
|
11
|
+
#
|
|
5
12
|
# r = []
|
|
6
13
|
# [:a, :b, :c, :d].step(2) { |x| r << x }
|
|
7
|
-
# r #=> [:
|
|
8
|
-
#
|
|
9
|
-
# Without a block it returns an Enumerator.
|
|
10
|
-
#
|
|
11
|
-
# [:a, :b, :c, :d].step(1).to_a #=> [:a, :b, :c, :d]
|
|
12
|
-
# [:a, :b, :c, :d].step(2).to_a #=> [:b, :d]
|
|
13
|
-
# [:a, :b, :c, :d].step(3).to_a #=> [:c]
|
|
14
|
-
# [:a, :b, :c, :d].step(5).to_a #=> []
|
|
14
|
+
# r #=> [:a, :c]
|
|
15
15
|
#
|
|
16
16
|
# CREDIT: Ryan Duryea
|
|
17
17
|
|
|
18
|
-
def step(n) #:yield:
|
|
18
|
+
def step(n, offset=0) #:yield:
|
|
19
19
|
if block_given?
|
|
20
|
-
(
|
|
20
|
+
(offset...size).step(n).each do |i|
|
|
21
21
|
yield(fetch(i))
|
|
22
22
|
end
|
|
23
23
|
else
|
|
24
|
-
Enumerator.new
|
|
25
|
-
(
|
|
24
|
+
Enumerator.new do |y|
|
|
25
|
+
(offset...size).step(n).each { |i| y << fetch(i) }
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
|
-
|
|
31
|
-
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
|
|
3
|
+
# Produces an array of ranges from the values in the array.
|
|
4
|
+
# Contiguous values and overlapping ranges are merged.
|
|
5
|
+
# Single values are returned as single-element ranges (e.g. 1..1).
|
|
6
|
+
#
|
|
7
|
+
# Examples
|
|
8
|
+
#
|
|
9
|
+
# [1,2,3,6,7,8].to_ranges #=> [1..3, 6..8]
|
|
10
|
+
#
|
|
11
|
+
# [3,4,5,1,6,9,8].to_ranges #=> [1..1, 3..6, 8..9]
|
|
12
|
+
#
|
|
13
|
+
# [10..15, 16..20, 21, 22].to_ranges #=> [10..22]
|
|
14
|
+
#
|
|
15
|
+
# Assumes inclusive ranges (i.e. 1..4) and range.first <= range.last.
|
|
16
|
+
#
|
|
17
|
+
# Works with integers, dates and strings. However, all the objects
|
|
18
|
+
# in the array must be of the same class.
|
|
19
|
+
#
|
|
20
|
+
# CREDIT: monocle, Ryan Duryea
|
|
21
|
+
|
|
22
|
+
def to_ranges
|
|
23
|
+
array = compact.uniq.sort_by { |e| Range === e ? e.first : e }
|
|
24
|
+
result = array.inject([]) do |c, value|
|
|
25
|
+
unless c.empty?
|
|
26
|
+
last = c.last
|
|
27
|
+
last_value = (Range === last ? last.last : last)
|
|
28
|
+
current_value = (Range === value ? value.first : value)
|
|
29
|
+
if (last_value.succ <=> current_value) == -1
|
|
30
|
+
c << value
|
|
31
|
+
else
|
|
32
|
+
first = (Range === last ? last.first : last)
|
|
33
|
+
second = [Range === last ? last.last : last, Range === value ? value.last : value].max
|
|
34
|
+
c[-1] = [first..second]
|
|
35
|
+
c.flatten!
|
|
36
|
+
end
|
|
37
|
+
else
|
|
38
|
+
c << value
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
# Ensure all elements are ranges
|
|
42
|
+
result.map { |e| Range === e ? e : e..e }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
alias arrange to_ranges
|
|
46
|
+
alias rangify to_ranges
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -9,11 +9,15 @@ class Array
|
|
|
9
9
|
# a.uniq_by!{ |i| i*i }
|
|
10
10
|
# a #=> [-5, -4, -3, -2, -1, 0]
|
|
11
11
|
#
|
|
12
|
+
# a = (-5..5).to_a.reverse
|
|
13
|
+
# a.uniq_by!{ |i| i*i }
|
|
14
|
+
# a #=> [5, 4, 3, 2, 1, 0]
|
|
15
|
+
#
|
|
12
16
|
# Returns [Array] of unique elements.
|
|
13
17
|
#
|
|
14
|
-
def uniq_by! #:yield:
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
def uniq_by!(&block) #:yield:
|
|
19
|
+
warn "Array#uniq_by! is deprecated. Use Array#uniq!(&block) instead.", uplevel: 1
|
|
20
|
+
uniq!(&block)
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
end
|