facets 1.8.49 → 1.8.51
Sign up to get free protection for your applications and to get access to all the features.
- data/PROJECT +4 -1
- data/Rakefile +25 -48
- data/VERSION +1 -1
- data/doc/AUTHORS +1 -0
- data/doc/CHANGES +6 -0
- data/lib/facets/core/kernel/tap.rb +33 -3
- data/lib/facets/more/command.rb +507 -271
- metadata +2 -548
- data/test/lib/facets/core/array/test_at_rand.rb +0 -34
- data/test/lib/facets/core/array/test_delete_unless.rb +0 -28
- data/test/lib/facets/core/array/test_delete_values.rb +0 -28
- data/test/lib/facets/core/array/test_delete_values_at.rb +0 -31
- data/test/lib/facets/core/array/test_first.rb +0 -46
- data/test/lib/facets/core/array/test_head.rb +0 -42
- data/test/lib/facets/core/array/test_last_index.rb +0 -26
- data/test/lib/facets/core/array/test_merge.rb +0 -35
- data/test/lib/facets/core/array/test_mid.rb +0 -33
- data/test/lib/facets/core/array/test_middle.rb +0 -29
- data/test/lib/facets/core/array/test_op_div.rb +0 -27
- data/test/lib/facets/core/array/test_op_fetch.rb +0 -35
- data/test/lib/facets/core/array/test_pad.rb +0 -48
- data/test/lib/facets/core/array/test_pick.rb +0 -40
- data/test/lib/facets/core/array/test_pos.rb +0 -28
- data/test/lib/facets/core/array/test_pot.rb +0 -28
- data/test/lib/facets/core/array/test_pull.rb +0 -28
- data/test/lib/facets/core/array/test_rand_index.rb +0 -29
- data/test/lib/facets/core/array/test_rand_subset.rb +0 -29
- data/test/lib/facets/core/array/test_range.rb +0 -32
- data/test/lib/facets/core/array/test_rotate.rb +0 -36
- data/test/lib/facets/core/array/test_select.rb +0 -28
- data/test/lib/facets/core/array/test_shuffle.rb +0 -35
- data/test/lib/facets/core/array/test_thru.rb +0 -27
- data/test/lib/facets/core/array/test_to_b.rb +0 -27
- data/test/lib/facets/core/array/test_to_h.rb +0 -33
- data/test/lib/facets/core/array/test_to_hash.rb +0 -27
- data/test/lib/facets/core/binding/self/test_of_caller.rb +0 -35
- data/test/lib/facets/core/binding/test___LINE__.rb +0 -43
- data/test/lib/facets/core/binding/test_call_stack.rb +0 -34
- data/test/lib/facets/core/binding/test_called.rb +0 -30
- data/test/lib/facets/core/binding/test_caller.rb +0 -35
- data/test/lib/facets/core/binding/test_defined.rb +0 -34
- data/test/lib/facets/core/binding/test_eval.rb +0 -34
- data/test/lib/facets/core/binding/test_local_variables.rb +0 -34
- data/test/lib/facets/core/binding/test_method_name.rb +0 -34
- data/test/lib/facets/core/binding/test_op_fetch.rb +0 -34
- data/test/lib/facets/core/binding/test_op_store.rb +0 -35
- data/test/lib/facets/core/binding/test_self.rb +0 -34
- data/test/lib/facets/core/class/test_cattr.rb +0 -63
- data/test/lib/facets/core/class/test_descendents.rb +0 -30
- data/test/lib/facets/core/class/test_method_name.rb +0 -26
- data/test/lib/facets/core/class/test_remove_descendents.rb +0 -32
- data/test/lib/facets/core/class/test_unix_path.rb +0 -26
- data/test/lib/facets/core/comparable/test_at_least.rb +0 -34
- data/test/lib/facets/core/comparable/test_clip.rb +0 -44
- data/test/lib/facets/core/comparable/test_cmp.rb +0 -28
- data/test/lib/facets/core/continuation/self/test_create.rb +0 -26
- data/test/lib/facets/core/date/test_days_in_month.rb +0 -30
- data/test/lib/facets/core/date/test_days_of_month.rb +0 -30
- data/test/lib/facets/core/date/test_stamp.rb +0 -38
- data/test/lib/facets/core/date/test_to_date.rb +0 -30
- data/test/lib/facets/core/date/test_to_s.rb +0 -30
- data/test/lib/facets/core/date/test_to_time.rb +0 -30
- data/test/lib/facets/core/dir/self/test_ancestor.rb +0 -26
- data/test/lib/facets/core/dir/self/test_ascend.rb +0 -41
- data/test/lib/facets/core/enumerable/self/test_combinations.rb +0 -46
- data/test/lib/facets/core/enumerable/test_cart.rb +0 -49
- data/test/lib/facets/core/enumerable/test_collect_with_index.rb +0 -27
- data/test/lib/facets/core/enumerable/test_commonality.rb +0 -31
- data/test/lib/facets/core/enumerable/test_compact_collect.rb +0 -27
- data/test/lib/facets/core/enumerable/test_count.rb +0 -38
- data/test/lib/facets/core/enumerable/test_each_by.rb +0 -71
- data/test/lib/facets/core/enumerable/test_each_combination.rb +0 -29
- data/test/lib/facets/core/enumerable/test_each_pair.rb +0 -29
- data/test/lib/facets/core/enumerable/test_each_slice.rb +0 -57
- data/test/lib/facets/core/enumerable/test_each_unique_pair.rb +0 -29
- data/test/lib/facets/core/enumerable/test_eachn.rb +0 -34
- data/test/lib/facets/core/enumerable/test_elementwise.rb +0 -40
- data/test/lib/facets/core/enumerable/test_entropy.rb +0 -26
- data/test/lib/facets/core/enumerable/test_every.rb +0 -35
- data/test/lib/facets/core/enumerable/test_ew.rb +0 -31
- data/test/lib/facets/core/enumerable/test_filter_collect.rb +0 -31
- data/test/lib/facets/core/enumerable/test_find_collisions.rb +0 -30
- data/test/lib/facets/core/enumerable/test_frequency.rb +0 -27
- data/test/lib/facets/core/enumerable/test_graph.rb +0 -30
- data/test/lib/facets/core/enumerable/test_ideal_entropy.rb +0 -27
- data/test/lib/facets/core/enumerable/test_none.rb +0 -33
- data/test/lib/facets/core/enumerable/test_occur.rb +0 -30
- data/test/lib/facets/core/enumerable/test_one.rb +0 -35
- data/test/lib/facets/core/enumerable/test_op_pow.rb +0 -27
- data/test/lib/facets/core/enumerable/test_op_tilde_self.rb +0 -40
- data/test/lib/facets/core/enumerable/test_partition_by.rb +0 -31
- data/test/lib/facets/core/enumerable/test_permutation.rb +0 -29
- data/test/lib/facets/core/enumerable/test_probability.rb +0 -27
- data/test/lib/facets/core/enumerable/test_to_h.rb +0 -27
- data/test/lib/facets/core/enumerable/test_uniq_by.rb +0 -28
- data/test/lib/facets/core/file/self/test_create.rb +0 -44
- data/test/lib/facets/core/file/self/test_open_as_string.rb +0 -50
- data/test/lib/facets/core/file/self/test_read_list.rb +0 -40
- data/test/lib/facets/core/file/self/test_sanitize.rb +0 -46
- data/test/lib/facets/core/file/self/test_split_all.rb +0 -27
- data/test/lib/facets/core/float/test_round_at.rb +0 -46
- data/test/lib/facets/core/float/test_round_to.rb +0 -46
- data/test/lib/facets/core/hash/self/test_zipnew.rb +0 -28
- data/test/lib/facets/core/hash/test_alias.rb +0 -31
- data/test/lib/facets/core/hash/test_assert_has_keys.rb +0 -27
- data/test/lib/facets/core/hash/test_assert_has_only_keys.rb +0 -27
- data/test/lib/facets/core/hash/test_at.rb +0 -28
- data/test/lib/facets/core/hash/test_collate.rb +0 -35
- data/test/lib/facets/core/hash/test_each_with_index.rb +0 -29
- data/test/lib/facets/core/hash/test_each_with_key.rb +0 -29
- data/test/lib/facets/core/hash/test_graph.rb +0 -28
- data/test/lib/facets/core/hash/test_has_keys.rb +0 -27
- data/test/lib/facets/core/hash/test_has_only_keys.rb +0 -27
- data/test/lib/facets/core/hash/test_inverse.rb +0 -30
- data/test/lib/facets/core/hash/test_normalize_keys.rb +0 -34
- data/test/lib/facets/core/hash/test_op_fetch.rb +0 -111
- data/test/lib/facets/core/hash/test_op_lshift.rb +0 -29
- data/test/lib/facets/core/hash/test_rand_key.rb +0 -27
- data/test/lib/facets/core/hash/test_rand_pair.rb +0 -27
- data/test/lib/facets/core/hash/test_rand_value.rb +0 -27
- data/test/lib/facets/core/hash/test_rekey.rb +0 -52
- data/test/lib/facets/core/hash/test_replace_each.rb +0 -29
- data/test/lib/facets/core/hash/test_shuffle.rb +0 -32
- data/test/lib/facets/core/hash/test_slice.rb +0 -27
- data/test/lib/facets/core/hash/test_stringify_keys.rb +0 -34
- data/test/lib/facets/core/hash/test_swap.rb +0 -27
- data/test/lib/facets/core/hash/test_swapkey.rb +0 -29
- data/test/lib/facets/core/hash/test_symbolize_keys.rb +0 -34
- data/test/lib/facets/core/hash/test_to_h.rb +0 -27
- data/test/lib/facets/core/hash/test_to_ostruct.rb +0 -30
- data/test/lib/facets/core/hash/test_to_ostruct_recurse.rb +0 -44
- data/test/lib/facets/core/hash/test_traverse.rb +0 -37
- data/test/lib/facets/core/hash/test_update_each.rb +0 -29
- data/test/lib/facets/core/hash/test_update_keys.rb +0 -28
- data/test/lib/facets/core/hash/test_update_values.rb +0 -28
- data/test/lib/facets/core/hash/test_weave.rb +0 -29
- data/test/lib/facets/core/integer/test_factorial.rb +0 -30
- data/test/lib/facets/core/integer/test_multiple.rb +0 -43
- data/test/lib/facets/core/integer/test_of.rb +0 -28
- data/test/lib/facets/core/integer/test_ordinal.rb +0 -29
- data/test/lib/facets/core/integer/test_times_collect.rb +0 -28
- data/test/lib/facets/core/kernel/test___class__.rb +0 -26
- data/test/lib/facets/core/kernel/test_as.rb +0 -42
- data/test/lib/facets/core/kernel/test_assign_from.rb +0 -31
- data/test/lib/facets/core/kernel/test_assign_with.rb +0 -31
- data/test/lib/facets/core/kernel/test_bool.rb +0 -41
- data/test/lib/facets/core/kernel/test_bug.rb +0 -26
- data/test/lib/facets/core/kernel/test_call_stack.rb +0 -26
- data/test/lib/facets/core/kernel/test_called.rb +0 -26
- data/test/lib/facets/core/kernel/test_callee.rb +0 -26
- data/test/lib/facets/core/kernel/test_constant.rb +0 -33
- data/test/lib/facets/core/kernel/test_copy.rb +0 -40
- data/test/lib/facets/core/kernel/test_deep_copy.rb +0 -40
- data/test/lib/facets/core/kernel/test_demo.rb +0 -28
- data/test/lib/facets/core/kernel/test_fn.rb +0 -26
- data/test/lib/facets/core/kernel/test_get_by_id.rb +0 -28
- data/test/lib/facets/core/kernel/test_here.rb +0 -26
- data/test/lib/facets/core/kernel/test_in.rb +0 -27
- data/test/lib/facets/core/kernel/test_instance_class.rb +0 -27
- data/test/lib/facets/core/kernel/test_instance_exec.rb +0 -58
- data/test/lib/facets/core/kernel/test_maybe.rb +0 -26
- data/test/lib/facets/core/kernel/test_meta_class.rb +0 -27
- data/test/lib/facets/core/kernel/test_metaclass.rb +0 -27
- data/test/lib/facets/core/kernel/test_method.rb +0 -32
- data/test/lib/facets/core/kernel/test_methods.rb +0 -50
- data/test/lib/facets/core/kernel/test_new.rb +0 -30
- data/test/lib/facets/core/kernel/test_object_class.rb +0 -26
- data/test/lib/facets/core/kernel/test_object_hexid.rb +0 -27
- data/test/lib/facets/core/kernel/test_qua_class.rb +0 -27
- data/test/lib/facets/core/kernel/test_require_all.rb +0 -26
- data/test/lib/facets/core/kernel/test_require_esc.rb +0 -27
- data/test/lib/facets/core/kernel/test_resc.rb +0 -27
- data/test/lib/facets/core/kernel/test_send_as.rb +0 -26
- data/test/lib/facets/core/kernel/test_set_from.rb +0 -33
- data/test/lib/facets/core/kernel/test_set_with.rb +0 -42
- data/test/lib/facets/core/kernel/test_silently.rb +0 -28
- data/test/lib/facets/core/kernel/test_singleton.rb +0 -40
- data/test/lib/facets/core/kernel/test_singleton_class.rb +0 -27
- data/test/lib/facets/core/kernel/test_super_at.rb +0 -30
- data/test/lib/facets/core/kernel/test_supermethod.rb +0 -33
- data/test/lib/facets/core/kernel/test_this.rb +0 -26
- data/test/lib/facets/core/kernel/test_to_b.rb +0 -28
- data/test/lib/facets/core/kernel/test_to_bool.rb +0 -28
- data/test/lib/facets/core/kernel/test_to_data.rb +0 -61
- data/test/lib/facets/core/kernel/test_uri.rb +0 -30
- data/test/lib/facets/core/kernel/test_val.rb +0 -43
- data/test/lib/facets/core/kernel/test_with.rb +0 -30
- data/test/lib/facets/core/kernel/test_with_accessor.rb +0 -51
- data/test/lib/facets/core/matchdata/test_match.rb +0 -29
- data/test/lib/facets/core/matchdata/test_matchtree.rb +0 -37
- data/test/lib/facets/core/module/self/test_op_add.rb +0 -50
- data/test/lib/facets/core/module/test_abstract.rb +0 -36
- data/test/lib/facets/core/module/test_alias_method_chain.rb +0 -46
- data/test/lib/facets/core/module/test_alias_module_function.rb +0 -34
- data/test/lib/facets/core/module/test_ancestor.rb +0 -26
- data/test/lib/facets/core/module/test_attr_tester.rb +0 -39
- data/test/lib/facets/core/module/test_basename.rb +0 -26
- data/test/lib/facets/core/module/test_by_name.rb +0 -29
- data/test/lib/facets/core/module/test_class_extension.rb +0 -70
- data/test/lib/facets/core/module/test_clone_using.rb +0 -55
- data/test/lib/facets/core/module/test_dirname.rb +0 -26
- data/test/lib/facets/core/module/test_equate_on.rb +0 -37
- data/test/lib/facets/core/module/test_include_as.rb +0 -45
- data/test/lib/facets/core/module/test_initializer.rb +0 -32
- data/test/lib/facets/core/module/test_instance_methods.rb +0 -59
- data/test/lib/facets/core/module/test_integrate.rb +0 -35
- data/test/lib/facets/core/module/test_memoize.rb +0 -50
- data/test/lib/facets/core/module/test_modspace.rb +0 -27
- data/test/lib/facets/core/module/test_namespace.rb +0 -66
- data/test/lib/facets/core/module/test_nesting.rb +0 -36
- data/test/lib/facets/core/module/test_new.rb +0 -34
- data/test/lib/facets/core/module/test_nodef.rb +0 -30
- data/test/lib/facets/core/module/test_on_included.rb +0 -36
- data/test/lib/facets/core/module/test_redef.rb +0 -30
- data/test/lib/facets/core/module/test_redefine_method.rb +0 -30
- data/test/lib/facets/core/module/test_redirect.rb +0 -30
- data/test/lib/facets/core/module/test_redirect_method.rb +0 -30
- data/test/lib/facets/core/module/test_remove.rb +0 -30
- data/test/lib/facets/core/module/test_rename.rb +0 -31
- data/test/lib/facets/core/module/test_rename_method.rb +0 -31
- data/test/lib/facets/core/module/test_revisal.rb +0 -35
- data/test/lib/facets/core/module/test_shadow_method.rb +0 -30
- data/test/lib/facets/core/module/test_sort_on.rb +0 -42
- data/test/lib/facets/core/module/test_this.rb +0 -31
- data/test/lib/facets/core/module/test_wrap.rb +0 -30
- data/test/lib/facets/core/module/test_wrap_method.rb +0 -30
- data/test/lib/facets/core/nilclass/test_blank.rb +0 -26
- data/test/lib/facets/core/nilclass/test_empty.rb +0 -26
- data/test/lib/facets/core/nilclass/test_include.rb +0 -26
- data/test/lib/facets/core/nilclass/test_op_fetch.rb +0 -28
- data/test/lib/facets/core/nilclass/test_size.rb +0 -30
- data/test/lib/facets/core/nilclass/test_to_h.rb +0 -26
- data/test/lib/facets/core/numeric/test_approx.rb +0 -29
- data/test/lib/facets/core/numeric/test_ceil_multiple.rb +0 -31
- data/test/lib/facets/core/numeric/test_distance.rb +0 -28
- data/test/lib/facets/core/numeric/test_succ.rb +0 -40
- data/test/lib/facets/core/numeric/test_to_b.rb +0 -27
- data/test/lib/facets/core/ostruct/test___update__.rb +0 -45
- data/test/lib/facets/core/ostruct/test_instance_delegate.rb +0 -36
- data/test/lib/facets/core/ostruct/test_op_fetch.rb +0 -33
- data/test/lib/facets/core/proc/test_compose.rb +0 -29
- data/test/lib/facets/core/proc/test_op_mul.rb +0 -34
- data/test/lib/facets/core/proc/test_to_method.rb +0 -44
- data/test/lib/facets/core/range/test_to_r.rb +0 -27
- data/test/lib/facets/core/range/test_to_range.rb +0 -27
- data/test/lib/facets/core/range/test_umbrella.rb +0 -34
- data/test/lib/facets/core/range/test_within.rb +0 -29
- data/test/lib/facets/core/regexp/test_arity.rb +0 -33
- data/test/lib/facets/core/regexp/test_to_re.rb +0 -27
- data/test/lib/facets/core/regexp/test_to_regexp.rb +0 -27
- data/test/lib/facets/core/string/self/test_interpolate.rb +0 -27
- data/test/lib/facets/core/string/self/test_patterns.rb +0 -28
- data/test/lib/facets/core/string/self/test_rand_letter.rb +0 -26
- data/test/lib/facets/core/string/test_align_center.rb +0 -34
- data/test/lib/facets/core/string/test_at_rand.rb +0 -35
- data/test/lib/facets/core/string/test_basename.rb +0 -41
- data/test/lib/facets/core/string/test_blank.rb +0 -27
- data/test/lib/facets/core/string/test_bracket.rb +0 -49
- data/test/lib/facets/core/string/test_bytes.rb +0 -25
- data/test/lib/facets/core/string/test_camelcase.rb +0 -39
- data/test/lib/facets/core/string/test_camelize.rb +0 -26
- data/test/lib/facets/core/string/test_capitalize_all.rb +0 -26
- data/test/lib/facets/core/string/test_capitalized.rb +0 -26
- data/test/lib/facets/core/string/test_chars.rb +0 -27
- data/test/lib/facets/core/string/test_cleave.rb +0 -43
- data/test/lib/facets/core/string/test_cmp.rb +0 -30
- data/test/lib/facets/core/string/test_demodulize.rb +0 -38
- data/test/lib/facets/core/string/test_divide.rb +0 -29
- data/test/lib/facets/core/string/test_downcase.rb +0 -26
- data/test/lib/facets/core/string/test_dresner.rb +0 -32
- data/test/lib/facets/core/string/test_each_char.rb +0 -29
- data/test/lib/facets/core/string/test_each_word.rb +0 -29
- data/test/lib/facets/core/string/test_first.rb +0 -43
- data/test/lib/facets/core/string/test_fold.rb +0 -34
- data/test/lib/facets/core/string/test_humanize.rb +0 -26
- data/test/lib/facets/core/string/test_indent.rb +0 -40
- data/test/lib/facets/core/string/test_index_all.rb +0 -26
- data/test/lib/facets/core/string/test_last.rb +0 -46
- data/test/lib/facets/core/string/test_line_wrap.rb +0 -27
- data/test/lib/facets/core/string/test_lines.rb +0 -26
- data/test/lib/facets/core/string/test_lowercase.rb +0 -26
- data/test/lib/facets/core/string/test_margin.rb +0 -117
- data/test/lib/facets/core/string/test_methodize.rb +0 -27
- data/test/lib/facets/core/string/test_modulize.rb +0 -29
- data/test/lib/facets/core/string/test_mscan.rb +0 -30
- data/test/lib/facets/core/string/test_natcmp.rb +0 -30
- data/test/lib/facets/core/string/test_nchar.rb +0 -29
- data/test/lib/facets/core/string/test_pathize.rb +0 -29
- data/test/lib/facets/core/string/test_pop.rb +0 -47
- data/test/lib/facets/core/string/test_pot.rb +0 -39
- data/test/lib/facets/core/string/test_push.rb +0 -40
- data/test/lib/facets/core/string/test_quote.rb +0 -49
- data/test/lib/facets/core/string/test_rand_byte.rb +0 -35
- data/test/lib/facets/core/string/test_rand_index.rb +0 -26
- data/test/lib/facets/core/string/test_range.rb +0 -27
- data/test/lib/facets/core/string/test_range_all.rb +0 -27
- data/test/lib/facets/core/string/test_range_of_line.rb +0 -28
- data/test/lib/facets/core/string/test_regesc.rb +0 -28
- data/test/lib/facets/core/string/test_shatter.rb +0 -29
- data/test/lib/facets/core/string/test_shift.rb +0 -40
- data/test/lib/facets/core/string/test_shuffle.rb +0 -27
- data/test/lib/facets/core/string/test_similarity.rb +0 -26
- data/test/lib/facets/core/string/test_singular.rb +0 -86
- data/test/lib/facets/core/string/test_soundex.rb +0 -41
- data/test/lib/facets/core/string/test_succ.rb +0 -29
- data/test/lib/facets/core/string/test_to_a.rb +0 -27
- data/test/lib/facets/core/string/test_to_b.rb +0 -41
- data/test/lib/facets/core/string/test_to_const.rb +0 -28
- data/test/lib/facets/core/string/test_to_date.rb +0 -30
- data/test/lib/facets/core/string/test_to_proc.rb +0 -33
- data/test/lib/facets/core/string/test_to_re.rb +0 -28
- data/test/lib/facets/core/string/test_to_time.rb +0 -30
- data/test/lib/facets/core/string/test_unix_crypt.rb +0 -30
- data/test/lib/facets/core/string/test_unpack.rb +0 -34
- data/test/lib/facets/core/string/test_unshift.rb +0 -39
- data/test/lib/facets/core/string/test_upcase.rb +0 -30
- data/test/lib/facets/core/string/test_whitespace.rb +0 -27
- data/test/lib/facets/core/string/test_word_filter.rb +0 -34
- data/test/lib/facets/core/string/test_word_wrap.rb +0 -51
- data/test/lib/facets/core/string/test_words.rb +0 -37
- data/test/lib/facets/core/symbol/test_camelcase.rb +0 -26
- data/test/lib/facets/core/symbol/test_camelize.rb +0 -27
- data/test/lib/facets/core/symbol/test_capitalize.rb +0 -26
- data/test/lib/facets/core/symbol/test_capitalized.rb +0 -27
- data/test/lib/facets/core/symbol/test_downcase.rb +0 -27
- data/test/lib/facets/core/symbol/test_not.rb +0 -29
- data/test/lib/facets/core/symbol/test_pad.rb +0 -27
- data/test/lib/facets/core/symbol/test_succ.rb +0 -28
- data/test/lib/facets/core/symbol/test_to_const.rb +0 -28
- data/test/lib/facets/core/symbol/test_to_proc.rb +0 -33
- data/test/lib/facets/core/symbol/test_to_str.rb +0 -28
- data/test/lib/facets/core/symbol/test_underscore.rb +0 -26
- data/test/lib/facets/core/symbol/test_upcase.rb +0 -27
- data/test/lib/facets/core/time/test_change.rb +0 -33
- data/test/lib/facets/core/time/test_elapse.rb +0 -27
- data/test/lib/facets/core/time/test_stamp.rb +0 -39
- data/test/lib/facets/core/time/test_to_date.rb +0 -31
- data/test/lib/facets/core/time/test_to_s.rb +0 -31
- data/test/lib/facets/core/time/test_to_time.rb +0 -31
- data/test/lib/facets/more/test_ann.rb +0 -112
- data/test/lib/facets/more/test_ann_attr.rb +0 -39
- data/test/lib/facets/more/test_ansicode.rb +0 -36
- data/test/lib/facets/more/test_arguments.rb +0 -83
- data/test/lib/facets/more/test_association.rb +0 -51
- data/test/lib/facets/more/test_autoarray.rb +0 -32
- data/test/lib/facets/more/test_basicobject.rb +0 -67
- data/test/lib/facets/more/test_bbcode.rb +0 -34
- data/test/lib/facets/more/test_binaryreader.rb +0 -64
- data/test/lib/facets/more/test_bitmask.rb +0 -47
- data/test/lib/facets/more/test_buildingblock.rb +0 -48
- data/test/lib/facets/more/test_bytes.rb +0 -84
- data/test/lib/facets/more/test_classmethods.rb +0 -69
- data/test/lib/facets/more/test_command.rb +0 -69
- data/test/lib/facets/more/test_coroutine.rb +0 -60
- data/test/lib/facets/more/test_crypt.rb +0 -46
- data/test/lib/facets/more/test_cut.rb +0 -198
- data/test/lib/facets/more/test_dependency.rb +0 -82
- data/test/lib/facets/more/test_dictionary.rb +0 -107
- data/test/lib/facets/more/test_elementor.rb +0 -52
- data/test/lib/facets/more/test_enumerablepass.rb +0 -86
- data/test/lib/facets/more/test_floatstring.rb +0 -36
- data/test/lib/facets/more/test_functor.rb +0 -39
- data/test/lib/facets/more/test_htmlbuilder.rb +0 -38
- data/test/lib/facets/more/test_htmlfilter.rb +0 -86
- data/test/lib/facets/more/test_infinity.rb +0 -50
- data/test/lib/facets/more/test_inheritor.rb +0 -155
- data/test/lib/facets/more/test_instance_intercept.rb +0 -50
- data/test/lib/facets/more/test_interval.rb +0 -119
- data/test/lib/facets/more/test_json.rb +0 -232
- data/test/lib/facets/more/test_linkedlist.rb +0 -53
- data/test/lib/facets/more/test_lisp.rb +0 -47
- data/test/lib/facets/more/test_lisp_format.rb +0 -37
- data/test/lib/facets/more/test_lrucache.rb +0 -25
- data/test/lib/facets/more/test_mathconstants.rb +0 -18
- data/test/lib/facets/more/test_methodfilter.rb +0 -45
- data/test/lib/facets/more/test_methodprobe.rb +0 -53
- data/test/lib/facets/more/test_multipliers.rb +0 -114
- data/test/lib/facets/more/test_multiton.rb +0 -199
- data/test/lib/facets/more/test_nackclass.rb +0 -45
- data/test/lib/facets/more/test_nilcomparable.rb +0 -47
- data/test/lib/facets/more/test_opencascade.rb +0 -75
- data/test/lib/facets/more/test_openobject.rb +0 -126
- data/test/lib/facets/more/test_overload.rb +0 -54
- data/test/lib/facets/more/test_paramix.rb +0 -100
- data/test/lib/facets/more/test_pqueue.rb +0 -39
- data/test/lib/facets/more/test_preinitialize.rb +0 -49
- data/test/lib/facets/more/test_promoteself.rb +0 -45
- data/test/lib/facets/more/test_recorder.rb +0 -44
- data/test/lib/facets/more/test_snapshot.rb +0 -34
- data/test/lib/facets/more/test_statichash.rb +0 -31
- data/test/lib/facets/more/test_syncarray.rb +0 -28
- data/test/lib/facets/more/test_synchash.rb +0 -28
- data/test/lib/facets/more/test_tagiterator.rb +0 -93
- data/test/lib/facets/more/test_timer.rb +0 -66
- data/test/lib/facets/more/test_times.rb +0 -103
- data/test/lib/facets/more/test_tuple.rb +0 -64
- data/test/lib/facets/more/test_typecast.rb +0 -68
- data/test/lib/facets/more/test_uninheritable.rb +0 -42
- data/test/lib/facets/more/test_units.rb +0 -111
- data/test/lib/facets/more/test_xmlbuilder.rb +0 -54
- data/test/lib/facets/more/test_xmlhelper.rb +0 -40
- data/test/lib/facets/more/test_xoxo.rb +0 -288
- data/test/lib/facets/more/test_yamlstruct.rb +0 -37
- data/test/lib/facets/yore/enumerable/test_cross.rb +0 -44
- data/test/lib/facets/yore/kernel/test_require_facet.rb +0 -27
- data/test/lib/facets/yore/module/test_namespace.rb +0 -33
- data/test/lib/facets/yore/test_annattr.rb +0 -39
- data/test/lib/facets/yore/test_annotation.rb +0 -318
- data/work/README +0 -42
- data/work/TODO +0 -73
- data/work/bin/minitar +0 -3
- data/work/bin/minitar.rb +0 -814
- data/work/core/array/at_rand.rb +0 -95
- data/work/core/array/each_slice.rb +0 -23
- data/work/core/array/pick_values.rb +0 -32
- data/work/core/array/rand_indexes.rb +0 -33
- data/work/core/binding/class.rb +0 -11
- data/work/core/binding/delegate-binding.rb +0 -19
- data/work/core/binding/delegate.rb +0 -15
- data/work/core/binding/proc.rb +0 -6
- data/work/core/class/to_module.rb +0 -3
- data/work/core/enumerable/op_fetch.rb +0 -30
- data/work/core/fileutils/cptouch.rb +0 -20
- data/work/core/fileutils/nl_convert.rb +0 -133
- data/work/core/io/expect.rb +0 -127
- data/work/core/join_with.rb +0 -13
- data/work/core/kernel/call_line.rb +0 -15
- data/work/core/kernel/does.rb +0 -7
- data/work/core/kernel/message.rb +0 -6
- data/work/core/kernel/query.rb +0 -15
- data/work/core/kernel/taint.rb +0 -10
- data/work/core/logger/clean_logger.rb +0 -10
- data/work/core/module/attr-old.rb +0 -308
- data/work/core/module/attr.rb +0 -98
- data/work/core/module/attr_xxx.rb +0 -22
- data/work/core/module/by_regexp.rb +0 -21
- data/work/core/module/cast.rb +0 -64
- data/work/core/module/class_attribute_accessors.rb +0 -57
- data/work/core/module/inherit.rb +0 -99
- data/work/core/module/inherit0.rb +0 -59
- data/work/core/module/let.rb +0 -51
- data/work/core/module/meta_attr.rb +0 -60
- data/work/core/module/module_attribute_accessors.rb +0 -57
- data/work/core/module/permissions.rb +0 -32
- data/work/core/module/preserved.rb +0 -108
- data/work/core/module/sattr_accessor.rb +0 -1
- data/work/core/module/sattr_reader.rb +0 -1
- data/work/core/module/sattr_setter.rb +0 -1
- data/work/core/module/sattr_tester.rb +0 -1
- data/work/core/module/sattr_writer.rb +0 -1
- data/work/core/module/tc_attr.rb +0 -107
- data/work/core/module/to_module.rb +0 -37
- data/work/core/module/version.rb +0 -23
- data/work/core/string/frequency.rb +0 -40
- data/work/core/string/op_add.rb +0 -24
- data/work/core/string/op_div.rb +0 -15
- data/work/core/string/pred.rb +0 -217
- data/work/core/string/probability.rb +0 -35
- data/work/core/string/succ_distance.rb +0 -112
- data/work/core/string/to_arr.rb +0 -57
- data/work/core/string/to_ary.rb +0 -12
- data/work/core/string/word_wrap.rb +0 -62
- data/work/hash_open.rb +0 -23
- data/work/misc/calibre/ProjectInfo.annotation +0 -46
- data/work/misc/calibre/ProjectInfo.ansicode +0 -33
- data/work/misc/calibre/ProjectInfo.association +0 -34
- data/work/misc/calibre/ProjectInfo.basicobject +0 -36
- data/work/misc/calibre/ProjectInfo.bbcode +0 -34
- data/work/misc/calibre/ProjectInfo.binaryreader +0 -35
- data/work/misc/calibre/ProjectInfo.bitmask +0 -33
- data/work/misc/calibre/ProjectInfo.classinherit +0 -36
- data/work/misc/calibre/ProjectInfo.classmethods +0 -36
- data/work/misc/calibre/ProjectInfo.cloneable +0 -33
- data/work/misc/calibre/ProjectInfo.consoleapp +0 -35
- data/work/misc/calibre/ProjectInfo.coroutine +0 -37
- data/work/misc/calibre/ProjectInfo.crypt +0 -33
- data/work/misc/calibre/ProjectInfo.dictionary +0 -40
- data/work/misc/calibre/ProjectInfo.downloader +0 -39
- data/work/misc/calibre/ProjectInfo.enumerablepass +0 -35
- data/work/misc/calibre/ProjectInfo.expirable +0 -37
- data/work/misc/calibre/ProjectInfo.floatstring +0 -35
- data/work/misc/calibre/ProjectInfo.functor +0 -40
- data/work/misc/calibre/ProjectInfo.heap +0 -33
- data/work/misc/calibre/ProjectInfo.inheritor +0 -36
- data/work/misc/calibre/ProjectInfo.interval +0 -36
- data/work/misc/calibre/ProjectInfo.lisp +0 -38
- data/work/misc/calibre/ProjectInfo.lrucache +0 -34
- data/work/misc/calibre/ProjectInfo.mathconstants +0 -41
- data/work/misc/calibre/ProjectInfo.methodprobe +0 -38
- data/work/misc/calibre/ProjectInfo.mock +0 -34
- data/work/misc/calibre/ProjectInfo.multiton +0 -36
- data/work/misc/calibre/ProjectInfo.nackclass +0 -33
- data/work/misc/calibre/ProjectInfo.nilcomparable +0 -35
- data/work/misc/calibre/ProjectInfo.nullclass +0 -35
- data/work/misc/calibre/ProjectInfo.one +0 -37
- data/work/misc/calibre/ProjectInfo.openobject +0 -39
- data/work/misc/calibre/ProjectInfo.paramix +0 -38
- data/work/misc/calibre/ProjectInfo.pool +0 -33
- data/work/misc/calibre/ProjectInfo.progressbar +0 -37
- data/work/misc/calibre/ProjectInfo.reference +0 -36
- data/work/misc/calibre/ProjectInfo.semaphore +0 -36
- data/work/misc/calibre/ProjectInfo.stateparser +0 -39
- data/work/misc/calibre/ProjectInfo.statichash +0 -33
- data/work/misc/calibre/ProjectInfo.system +0 -34
- data/work/misc/calibre/ProjectInfo.tagiterator +0 -36
- data/work/misc/calibre/ProjectInfo.timer +0 -35
- data/work/misc/calibre/ProjectInfo.tracepoint +0 -37
- data/work/misc/calibre/ProjectInfo.tuple +0 -36
- data/work/misc/calibre/ProjectInfo.uniheritable +0 -34
- data/work/misc/calibre/ProjectInfo.units +0 -34
- data/work/misc/calibre/ProjectInfo.yamlstruct +0 -34
- data/work/more/annotation-rw.rb +0 -217
- data/work/more/aobject.rb +0 -132
- data/work/more/autohash.rb +0 -67
- data/work/more/cache.rb +0 -189
- data/work/more/class_inheritable_attributes.rb +0 -120
- data/work/more/commandrunner.rb +0 -101
- data/work/more/daemon.rb +0 -70
- data/work/more/debugger.rb +0 -167
- data/work/more/detach.rb +0 -423
- data/work/more/enumtype.rb +0 -115
- data/work/more/ioreactor.rb +0 -671
- data/work/more/logger_sing.rb +0 -207
- data/work/more/must.rb +0 -37
- data/work/more/old-tkxml.rb +0 -189
- data/work/more/pairhash.rb +0 -55
- data/work/more/password.rb +0 -80
- data/work/more/print_exception.rb +0 -35
- data/work/more/rand.rb +0 -412
- data/work/more/range.rb +0 -383
- data/work/more/sanitize.rb +0 -48
- data/work/more/superstruct.rb +0 -735
- data/work/more/tag.rb +0 -31
- data/work/more/timer.rb +0 -164
- data/work/op_rshift.rb +0 -87
- data/work/openobject-temp.rb +0 -45
- data/work/pore/autorequire.rb +0 -83
- data/work/pore/basefactory.rb +0 -40
- data/work/pore/hash/each.rb +0 -76
- data/work/pore/merge3.rb +0 -765
- data/work/pore/superann.rb +0 -134
- data/work/pore/sys.rb +0 -186
- data/work/pore/utils.rb +0 -518
- data/work/yore/HashAquisition.rb +0 -36
- data/work/yore/Rakefile.old +0 -181
- data/work/yore/Reapfile +0 -63
- data/work/yore/annotation.rb +0 -489
- data/work/yore/annotation2.rb +0 -466
- data/work/yore/commandutils.rb +0 -379
- data/work/yore/openobject.rb +0 -298
- data/work/yore/reap.rb +0 -184
- data/work/yore/reap.yml +0 -47
- data/work/yore/taskable-old.rb +0 -519
- data/work/yore/taskable.rb +0 -482
data/work/more/range.rb
DELETED
@@ -1,383 +0,0 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
|
3
|
-
= Descrete Range Class
|
4
|
-
|
5
|
-
This is the Range class slightly modified to be truly desecrete in nature.
|
6
|
-
Use the Interval class (see interval.rb) for a truly continuious range class.
|
7
|
-
|
8
|
-
== Synopsis
|
9
|
-
|
10
|
-
The following code uses class +Xs+, which is defined in the
|
11
|
-
class-level documentation.
|
12
|
-
|
13
|
-
require 'trix/range'
|
14
|
-
|
15
|
-
range = Xs.new(1)..Xs.new(10)
|
16
|
-
range.step(2) {|x| puts x}
|
17
|
-
range.step(3) {|x| puts x}
|
18
|
-
|
19
|
-
_produces:_
|
20
|
-
|
21
|
-
1 x
|
22
|
-
3 xxx
|
23
|
-
5 xxxxx
|
24
|
-
7 xxxxxxx
|
25
|
-
9 xxxxxxxxx
|
26
|
-
1 x
|
27
|
-
4 xxxx
|
28
|
-
7 xxxxxxx
|
29
|
-
10 xxxxxxxxxx
|
30
|
-
|
31
|
-
== Notes
|
32
|
-
|
33
|
-
Range is not quite have descrete behavior becasue it also performs
|
34
|
-
double-duty as a continious interval class. Its just a bit too overloaded
|
35
|
-
and this limits its full potential. To remedy, a separate Interval class
|
36
|
-
has been created to handle true interval functionality. And here we
|
37
|
-
adjust Range to be truely discrete.
|
38
|
-
|
39
|
-
Range originally dependened on two methods: #succ and #<=>. If numeric
|
40
|
-
ranges were the only concern, those could just as well be #+ and #<=>,
|
41
|
-
but esoteric forms make that unfeasible --the obvious example being a
|
42
|
-
String range. To properly handle this, Range fully seperates and extends
|
43
|
-
the parallel methods: #succ for #+, #cmp for #<=> ( in the future we may
|
44
|
-
add #pred for #- ). It also adds the option of #distance to properly
|
45
|
-
calculate the difference between the sentinals. This is neccessary
|
46
|
-
to ensure congruent bahavior. For instance, presently String Range's
|
47
|
-
can give bad results because #<=> does not measure order in the same
|
48
|
-
manner that #succ generates order.
|
49
|
-
|
50
|
-
== Todo List
|
51
|
-
|
52
|
-
* Add skip parameter, to allow skip-ranges, i.e. skipping successive iterations.
|
53
|
-
|
54
|
-
== Author
|
55
|
-
|
56
|
-
* Thomas Sawyer
|
57
|
-
|
58
|
-
=end
|
59
|
-
|
60
|
-
require 'carat/infinity'
|
61
|
-
require 'carat/interval'
|
62
|
-
|
63
|
-
|
64
|
-
class Range
|
65
|
-
|
66
|
-
alias_method :initialize_simple, :initialize
|
67
|
-
private :initialize_simple
|
68
|
-
|
69
|
-
def initialize( first, halt, exclude_last=false, &succ )
|
70
|
-
@first = first
|
71
|
-
@last = halt.kind_of?(Proc) ? nil : halt
|
72
|
-
@halt = @last ? nil : halt
|
73
|
-
#@exclude_first = exclude_first
|
74
|
-
@exclude_last = exclude_last
|
75
|
-
@direction = (@last <=> @first)
|
76
|
-
#@direction = 1 if @direction == 0
|
77
|
-
@succ = succ || nil #@first.method(:succ).to_proc
|
78
|
-
#@halt = nil #exclude_last? ? proc{ |x| x.cmp(@last) != -1 } : proc{ |x| x.cmp(@last) == 1 }
|
79
|
-
initialize_simple(@first, @last, @exclude_last)
|
80
|
-
end
|
81
|
-
|
82
|
-
def succ ; @succ ; end
|
83
|
-
|
84
|
-
def succ!(s)
|
85
|
-
if @succ
|
86
|
-
@succ.call(s)
|
87
|
-
else
|
88
|
-
s.succ
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def succ=(succ_proc)
|
93
|
-
raise ArgumentError unless Proc === succ_proc
|
94
|
-
@succ = succ_proc
|
95
|
-
end
|
96
|
-
|
97
|
-
def halt ; @halt ; end
|
98
|
-
|
99
|
-
def halt?(s)
|
100
|
-
if @halt
|
101
|
-
@halt.call(s)
|
102
|
-
else
|
103
|
-
if @exclude_last
|
104
|
-
s.cmp(@last) != -1
|
105
|
-
else
|
106
|
-
s.cmp(@last) == 1
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def halt=(halt_proc)
|
112
|
-
raise ArgumentError unless Proc === halt_proc
|
113
|
-
@halt = halt_proc
|
114
|
-
end
|
115
|
-
|
116
|
-
#def first ; @first ; end
|
117
|
-
#def last ; @last ; end
|
118
|
-
#def exclude_first? ; @exclude_first ; end
|
119
|
-
#def exclude_last? ; @exclude_last ; end
|
120
|
-
alias exclude_last? exclude_end?
|
121
|
-
|
122
|
-
def direction
|
123
|
-
@direction ||= (@last <=> @first)
|
124
|
-
end
|
125
|
-
|
126
|
-
# poor names
|
127
|
-
#undef_method :begin
|
128
|
-
#undef_method :end
|
129
|
-
#undef_method :exclude_end?
|
130
|
-
|
131
|
-
def -@ ; Range.new( @first, @last, true, &@succ ) ; end
|
132
|
-
|
133
|
-
def distance
|
134
|
-
return @last.distance(@first) if @last and @last.respond_to?(:distance)
|
135
|
-
self.to_a.length # should it just be nil instead?
|
136
|
-
end
|
137
|
-
alias_method( :length, :distance )
|
138
|
-
alias_method( :size, :distance )
|
139
|
-
|
140
|
-
def min
|
141
|
-
(@first.cmp(@last) == -1) ? @first : @last
|
142
|
-
end
|
143
|
-
|
144
|
-
def max
|
145
|
-
(@first.cmp(@last) == 1) ? @first : @last
|
146
|
-
end
|
147
|
-
|
148
|
-
# +between?+ simply tests whether the given value falls
|
149
|
-
# between the sentinels by comparison. It does not
|
150
|
-
# verify that the value is acutally in the range's sequence.
|
151
|
-
def between?(x)
|
152
|
-
#tf = exclude_first? ? 1 : 0
|
153
|
-
tl = exclude_last? ? -1 : 0
|
154
|
-
# if other classes handled Infinity in their <=> method
|
155
|
-
# (which probably they should) this clause would not be required
|
156
|
-
if first.kind_of?(InfinityClass)
|
157
|
-
ft = ((first <=> x) <= tf)
|
158
|
-
else
|
159
|
-
ft = (x <=> first) >= tf
|
160
|
-
end
|
161
|
-
if last.kind_of?(InfinityClass)
|
162
|
-
fl = ((last <=> x) >= tl)
|
163
|
-
else
|
164
|
-
fl = (x <=> last) <= tl
|
165
|
-
end
|
166
|
-
ft && fl
|
167
|
-
end
|
168
|
-
|
169
|
-
# Is this proper alias of +===+?
|
170
|
-
alias_method( :===, :between? )
|
171
|
-
|
172
|
-
# +include?+ is an alias for +member?+. It is like between
|
173
|
-
# but makes sure that the value is in the range sequence.
|
174
|
-
alias_method( :include?, :member? )
|
175
|
-
|
176
|
-
# Compares two ranges to see if they are equal
|
177
|
-
def eql?(other)
|
178
|
-
return false unless @first == other.first
|
179
|
-
other_last = other.exclude_last? ? other.last : other.last
|
180
|
-
if self.exclude_last? and not other.exclude_last?
|
181
|
-
return false unless self.last == other.last.succ
|
182
|
-
elsif other.exclude_last? and not self.exclude_last?
|
183
|
-
return false unless self.last.succ == other.last
|
184
|
-
else
|
185
|
-
return false unless @last == other.last
|
186
|
-
end
|
187
|
-
true
|
188
|
-
end
|
189
|
-
|
190
|
-
alias each_succ each
|
191
|
-
def each( &blk )
|
192
|
-
return each_succ( &blk ) unless @succ or @halt
|
193
|
-
if @halt
|
194
|
-
halt_proc = @halt
|
195
|
-
else
|
196
|
-
halt_proc = exclude_last? ? proc{ |x| x.cmp(@last) != -1 } : proc{ |x| x.cmp(@last) == 1 }
|
197
|
-
end
|
198
|
-
#t = exclude_last? ? -1 : 0
|
199
|
-
s = @first
|
200
|
-
if @succ
|
201
|
-
#while (s <=> @last) == -1 or (s <=> @last) == t
|
202
|
-
until halt_proc.call(s)
|
203
|
-
yield(s)
|
204
|
-
@succ.call(s)
|
205
|
-
end
|
206
|
-
else
|
207
|
-
#while (s <=> @last) == -1 or (s <=> @last) == t
|
208
|
-
until halt_proc.call(s)
|
209
|
-
yield(s)
|
210
|
-
s.succ
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
# # each(n) where n is steps, if n is negative it is nth
|
216
|
-
# # I know, it's a neg num trick :( but I think it's
|
217
|
-
# # better then having another method like #each_nth,
|
218
|
-
# # cause then you'd need #to_a_nth, too, etc.
|
219
|
-
# def each(n=1) # :yield:
|
220
|
-
# n = (length / n.abs) if n < 0
|
221
|
-
# n = n * direction
|
222
|
-
# i = first; i.succ(n) if exclude_first?
|
223
|
-
# t = exclude_last? ? -1 : 0
|
224
|
-
# while (i <=> last) == -1 or (i <=> last) == t
|
225
|
-
# yield(i)
|
226
|
-
# i.succ(n)
|
227
|
-
# end
|
228
|
-
# end
|
229
|
-
|
230
|
-
# # each(n) where n is steps, if n is negative it is nth
|
231
|
-
# # I know, it's a neg num trick :( but I think it's
|
232
|
-
# # better then having another method like #each_nth,
|
233
|
-
# # cause then you'd need #to_a_nth, too, etc.
|
234
|
-
# def reverse_each(n=1) # :yield:
|
235
|
-
# n = (length / n.abs) if n < 0
|
236
|
-
# n = n * direction
|
237
|
-
# i = last; i -= n if exclude_first?
|
238
|
-
# t = exclude_first? ? 1 : 0
|
239
|
-
# while (i <=> first) == 1 or (i <=> first) == t
|
240
|
-
# yield(i)
|
241
|
-
# i += n
|
242
|
-
# end
|
243
|
-
# end
|
244
|
-
|
245
|
-
# def to_a(n=1)
|
246
|
-
# a=[]; each(n){|e| a << e}
|
247
|
-
# a
|
248
|
-
# end
|
249
|
-
|
250
|
-
# Is this even desirable at this point?
|
251
|
-
# Sequences depend on #succ rather then #+
|
252
|
-
# so don't expect the same results from each!
|
253
|
-
# def to_seq
|
254
|
-
# seed = exclude_first? ? first.succ : first
|
255
|
-
# halt = exclude_last? ? proc{|x| (x <=> last) >= 0} : proc{|x| (x <=> last) > 0}
|
256
|
-
# Sequence.new( seed, &halt )
|
257
|
-
# end
|
258
|
-
|
259
|
-
end
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
=begin test
|
264
|
-
|
265
|
-
|
266
|
-
require 'test/unit'
|
267
|
-
|
268
|
-
class GeneralTest < Test::Unit::TestCase
|
269
|
-
|
270
|
-
def test_include_001
|
271
|
-
a = Range.new(1,10)
|
272
|
-
assert_equal(false, a.include?(0))
|
273
|
-
assert_equal(true, a.include?(1))
|
274
|
-
assert_equal(true, a.include?(2))
|
275
|
-
assert_equal(true, a.include?(9))
|
276
|
-
assert_equal(true, a.include?(10))
|
277
|
-
assert_equal(false, a.include?(11))
|
278
|
-
end
|
279
|
-
|
280
|
-
def test_include_002
|
281
|
-
a = Range.new(1,10,false,true)
|
282
|
-
assert_equal(false, a.include?(0))
|
283
|
-
assert_equal(true, a.include?(1))
|
284
|
-
assert_equal(true, a.include?(2))
|
285
|
-
assert_equal(true, a.include?(9))
|
286
|
-
assert_equal(false, a.include?(10))
|
287
|
-
assert_equal(false, a.include?(11))
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_include_003
|
291
|
-
a = Range.new(1,10,true,false)
|
292
|
-
assert_equal(false, a.include?(0))
|
293
|
-
assert_equal(false, a.include?(1))
|
294
|
-
assert_equal(true, a.include?(2))
|
295
|
-
assert_equal(true, a.include?(9))
|
296
|
-
assert_equal(true, a.include?(10))
|
297
|
-
assert_equal(false, a.include?(11))
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_include_004
|
301
|
-
a = Range.new(1,10,true,true)
|
302
|
-
assert_equal(false, a.include?(0))
|
303
|
-
assert_equal(false, a.include?(1))
|
304
|
-
assert_equal(true, a.include?(2))
|
305
|
-
assert_equal(true, a.include?(9))
|
306
|
-
assert_equal(false, a.include?(10))
|
307
|
-
assert_equal(false, a.include?(11))
|
308
|
-
end
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
class LrgNumericTest < Test::Unit::TestCase
|
313
|
-
def test_include
|
314
|
-
a = Range.new(0,100000000)
|
315
|
-
assert_equal(true, a.include?(0))
|
316
|
-
assert_equal(true, a.include?(1000))
|
317
|
-
assert_equal(true, a.include?(1000000))
|
318
|
-
assert_equal(true, a.include?(100000000))
|
319
|
-
assert_equal(false, a.include?(INFINITY))
|
320
|
-
end
|
321
|
-
def test_include_with_step
|
322
|
-
a = Range.new(0,100000000)
|
323
|
-
assert_equal(true, a.include?(0))
|
324
|
-
assert_equal(true, a.include?(5))
|
325
|
-
assert_equal(true, a.include?(70007))
|
326
|
-
assert_equal(true, a.include?(5000005))
|
327
|
-
assert_equal(false, a.include?(INFINITY))
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
class InfTest < Test::Unit::TestCase
|
332
|
-
def test_include?
|
333
|
-
a = Range.new(-INFINITY,-3)
|
334
|
-
assert_equal(true, a.include?(-INFINITY))
|
335
|
-
assert_equal(true, a.include?(-4))
|
336
|
-
assert_equal(true, a.include?(-3))
|
337
|
-
assert_equal(false, a.include?(-2))
|
338
|
-
assert_equal(false, a.include?(INFINITY))
|
339
|
-
a = Range.new(-INFINITY,-3,false,true)
|
340
|
-
assert_equal(true, a.include?(-INFINITY))
|
341
|
-
assert_equal(true, a.include?(-4))
|
342
|
-
assert_equal(false, a.include?(-3))
|
343
|
-
assert_equal(false, a.include?(-2))
|
344
|
-
assert_equal(false, a.include?(INFINITY))
|
345
|
-
a = Range.new(-3,INFINITY)
|
346
|
-
assert_equal(false, a.include?(-INFINITY))
|
347
|
-
assert_equal(false, a.include?(-4))
|
348
|
-
assert_equal(true, a.include?(-3))
|
349
|
-
assert_equal(true, a.include?(-2))
|
350
|
-
assert_equal(true, a.include?(INFINITY))
|
351
|
-
a = Range.new(-INFINITY,INFINITY)
|
352
|
-
assert_equal(true, a.include?(-INFINITY))
|
353
|
-
assert_equal(true, a.include?(-4))
|
354
|
-
assert_equal(true, a.include?(-3))
|
355
|
-
assert_equal(true, a.include?(-2))
|
356
|
-
assert_equal(true, a.include?(INFINITY))
|
357
|
-
a = Range.new(-3,-2)
|
358
|
-
assert_equal(false, a.include?(-INFINITY))
|
359
|
-
assert_equal(false, a.include?(-4))
|
360
|
-
assert_equal(true, a.include?(-3))
|
361
|
-
assert_equal(true, a.include?(-2))
|
362
|
-
assert_equal(false, a.include?(INFINITY))
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
class OrdinalTest < Test::Unit::TestCase
|
367
|
-
def test_include
|
368
|
-
a = Range.new('a','g')
|
369
|
-
#assert_equal(false, a.include?(-INFINITY))
|
370
|
-
assert_equal(true, a.include?('a'))
|
371
|
-
assert_equal(true, a.include?('c'))
|
372
|
-
assert_equal(false, a.include?('z'))
|
373
|
-
#assert_equal(false, a.include?(INFINITY))
|
374
|
-
end
|
375
|
-
#def test_error
|
376
|
-
# assert_raises(ArgumentError) {
|
377
|
-
# a = (-INFINITY..'z')
|
378
|
-
# }
|
379
|
-
#end
|
380
|
-
end
|
381
|
-
|
382
|
-
=end
|
383
|
-
|
data/work/more/sanitize.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# Code from rubyonrails project (http://www.rubyonrails.com)
|
2
|
-
# Temporarily here.
|
3
|
-
|
4
|
-
require 'html/tokenizer'
|
5
|
-
require 'html/node'
|
6
|
-
|
7
|
-
VERBOTEN_TAGS = %w(form script) unless defined?(VERBOTEN_TAGS)
|
8
|
-
VERBOTEN_ATTRS = /^on/i unless defined?(VERBOTEN_ATTRS)
|
9
|
-
|
10
|
-
class String
|
11
|
-
# Sanitizes the given HTML by making form and script tags into regular
|
12
|
-
# text, and removing all "onxxx" attributes (so that arbitrary Javascript
|
13
|
-
# cannot be executed). Also removes href attributes that start with
|
14
|
-
# "javascript:".
|
15
|
-
#
|
16
|
-
# Returns the sanitized text.
|
17
|
-
def self.sanitize(html)
|
18
|
-
# only do this if absolutely necessary
|
19
|
-
if html.index("<")
|
20
|
-
tokenizer = HTML::Tokenizer.new(html)
|
21
|
-
new_text = ""
|
22
|
-
|
23
|
-
while token = tokenizer.next
|
24
|
-
node = HTML::Node.parse(nil, 0, 0, token, false)
|
25
|
-
new_text << case node
|
26
|
-
when HTML::Tag
|
27
|
-
if VERBOTEN_TAGS.include?(node.name)
|
28
|
-
node.to_s.gsub(/</, "<")
|
29
|
-
else
|
30
|
-
if node.closing != :close
|
31
|
-
node.attributes.delete_if { |attr,v| attr =~ VERBOTEN_ATTRS }
|
32
|
-
if node.attributes["href"] =~ /^javascript:/i
|
33
|
-
node.attributes.delete "href"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
node.to_s
|
37
|
-
end
|
38
|
-
else
|
39
|
-
node.to_s.gsub(/</, "<")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
html = new_text
|
44
|
-
end
|
45
|
-
|
46
|
-
html
|
47
|
-
end
|
48
|
-
end
|
data/work/more/superstruct.rb
DELETED
@@ -1,735 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# SuperStruct
|
3
|
-
# Copyright (c) 2005 Hal Fulton
|
4
|
-
#
|
5
|
-
# Ruby License
|
6
|
-
#
|
7
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
-
# software under the same terms as Ruby.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
-
# FOR A PARTICULAR PURPOSE.
|
13
|
-
#++
|
14
|
-
|
15
|
-
# = SuperStruct
|
16
|
-
#
|
17
|
-
# This is an easy way to create Struct-like classes; it converts easily
|
18
|
-
# between hashes and arrays, and it allows OpenStruct-like dynamic naming
|
19
|
-
# of members.
|
20
|
-
#
|
21
|
-
# Unlike Struct, it creates a "real" class, and it has real instance variables
|
22
|
-
# with predictable names.
|
23
|
-
#
|
24
|
-
# A basic limitation is that the hash keys must be legal method names (unless
|
25
|
-
# used with send()).
|
26
|
-
#
|
27
|
-
# Basically, ss["alpha"], ss[:alpha], ss[0], and ss.alpha all mean the same.
|
28
|
-
#
|
29
|
-
# == What It's Like
|
30
|
-
#
|
31
|
-
# It's like a Struct...
|
32
|
-
# - you can pass in a list of symbols for accessors
|
33
|
-
# - it will create a class for you
|
34
|
-
# but...
|
35
|
-
# - you don't have to pass in the class name
|
36
|
-
# - it returns a "real" class
|
37
|
-
# . instance variables have the expected names
|
38
|
-
# . you can reopen and add methods
|
39
|
-
# - it doesn't go into the Struct:: namespace
|
40
|
-
# - it preserves the order of the fields
|
41
|
-
# - you can use Strings instead of Symbols for the names
|
42
|
-
#
|
43
|
-
# It's like an Array...
|
44
|
-
# - you can access the items by [number] and [number]=
|
45
|
-
# but...
|
46
|
-
# - you can also access the items by ["name"] and ["name"]=
|
47
|
-
# - you can access the items by accessors
|
48
|
-
#
|
49
|
-
# It's like an OpenStruct...
|
50
|
-
# - (if you use .open instead of .new) you can add fields
|
51
|
-
# automatically with x.field or x.field=val
|
52
|
-
# but...
|
53
|
-
# - you can initialize it like a Struct
|
54
|
-
# - it preserves the order of the fields
|
55
|
-
#
|
56
|
-
# It's like a Hash...
|
57
|
-
# - data can be accessed by ["name"]
|
58
|
-
# but...
|
59
|
-
# - order (of entry or creation) is preserved
|
60
|
-
# - arbitrary objects are not allowed (it does obj.to_str or obj.to_s)
|
61
|
-
# - strings must be valid method names
|
62
|
-
#
|
63
|
-
# It's like Ara Howard's Named Array...
|
64
|
-
# - we can access elements by ["name"] or ["name"]=
|
65
|
-
# but...
|
66
|
-
# - you can access the items by accessors
|
67
|
-
# - strings must be valid method names
|
68
|
-
#
|
69
|
-
# It's like Florian Gross's Keyed List...
|
70
|
-
# (to be done)
|
71
|
-
# but...
|
72
|
-
# - it preserves the order of the fields
|
73
|
-
#
|
74
|
-
# == Usage
|
75
|
-
#
|
76
|
-
# # Need not assign to existing fields (default to nil)
|
77
|
-
# myStruct = SuperStruct.new(:alpha)
|
78
|
-
# x = myStruct.new
|
79
|
-
# x.alpha # nil
|
80
|
-
#
|
81
|
-
# # A value assigned at construction may be retrieved
|
82
|
-
# myStruct = SuperStruct.new(:alpha)
|
83
|
-
# x = myStruct.new(234)
|
84
|
-
# x.alpha # 234
|
85
|
-
#
|
86
|
-
# # Unassigned fields are nil
|
87
|
-
# myStruct = SuperStruct.new(:alpha,:beta)
|
88
|
-
# x = myStruct.new(234)
|
89
|
-
# x.beta # nil
|
90
|
-
#
|
91
|
-
# # An open structure may not construct with nonexistent fields
|
92
|
-
# myStruct = SuperStruct.open
|
93
|
-
# x = myStruct.new(234) # error
|
94
|
-
#
|
95
|
-
# # An open structure may assign fields not previously existing
|
96
|
-
# myStruct = SuperStruct.open
|
97
|
-
# x = myStruct.new
|
98
|
-
# x.foo = 123
|
99
|
-
# x.bar = 456
|
100
|
-
#
|
101
|
-
# # The act of retrieving a nonexistent field from an open struct will
|
102
|
-
# # create that field
|
103
|
-
# myStruct = SuperStruct.open
|
104
|
-
# x = myStruct.new
|
105
|
-
# x.foo # nil
|
106
|
-
#
|
107
|
-
# # A field (in an open struct) that is unassigned will be nil
|
108
|
-
# myStruct = SuperStruct.open
|
109
|
-
# x = myStruct.new
|
110
|
-
# y = x.foobar
|
111
|
-
#
|
112
|
-
# # A struct created with new rather than open cannot reference nonexistent
|
113
|
-
# # fields
|
114
|
-
# myStruct = SuperStruct.new
|
115
|
-
# x = myStruct.new
|
116
|
-
# x.foo # error
|
117
|
-
#
|
118
|
-
# # Adding a field to a struct will create a writer and reader for that field
|
119
|
-
#
|
120
|
-
# # An open struct will also create a writer and a reader together
|
121
|
-
#
|
122
|
-
# # A field has a real writer and reader corresponding to it
|
123
|
-
#
|
124
|
-
# # A string will work as well as a symbol
|
125
|
-
# myStruct = SuperStruct.new("alpha")
|
126
|
-
#
|
127
|
-
# # to_a will return an array of values
|
128
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
129
|
-
# x = myStruct.new(7,8,9)
|
130
|
-
# assert(x.to_a == [7,8,9])
|
131
|
-
#
|
132
|
-
# # Instance method 'members' will return a list of members (as strings)
|
133
|
-
# myStruct = SuperStruct.new(:alpha,"beta")
|
134
|
-
# x = myStruct.new
|
135
|
-
# assert_equal(["alpha","beta"],x.members)
|
136
|
-
#
|
137
|
-
# # Class method 'members' will return a list of members (as strings)
|
138
|
-
# myStruct = SuperStruct.new(:alpha,"beta")
|
139
|
-
# assert_equal(["alpha","beta"],myStruct.members)
|
140
|
-
#
|
141
|
-
# # to_ary will allow a struct to be treated like an array in
|
142
|
-
# # multiple assignment
|
143
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
144
|
-
# x = myStruct.new(7,8,9)
|
145
|
-
# a,b,c = x
|
146
|
-
# assert(b == 8)
|
147
|
-
#
|
148
|
-
# # to_ary will allow a struct to be treated like an array in
|
149
|
-
# # passed parameters
|
150
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
151
|
-
# x = myStruct.new(7,8,9)
|
152
|
-
# b = meth(*x)
|
153
|
-
#
|
154
|
-
# # to_hash will return a hash with fields as keys
|
155
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
156
|
-
# x = myStruct.new(7,8,9)
|
157
|
-
# h = x.to_hash
|
158
|
-
# assert_equal({"alpha"=>7,"beta"=>8,"gamma"=>9},h)
|
159
|
-
#
|
160
|
-
# # A field name (String) may be used in a hash-like notation
|
161
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
162
|
-
# x = myStruct.new(7,8,9)
|
163
|
-
# y = x["beta"]
|
164
|
-
#
|
165
|
-
# # A field name (Symbol) may be used in a hash-like notation
|
166
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
167
|
-
# x = myStruct.new(7,8,9)
|
168
|
-
# y = x[:beta]
|
169
|
-
#
|
170
|
-
# # [offset,length] may be used as for arrays
|
171
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
172
|
-
# x = myStruct.new(7,8,9)
|
173
|
-
# y = x[0,2]
|
174
|
-
#
|
175
|
-
# # Ranges may be used as for arrays
|
176
|
-
# myStruct = SuperStruct.new("alpha","beta","gamma")
|
177
|
-
# x = myStruct.new(7,8,9)
|
178
|
-
# y = x[1..2]
|
179
|
-
#
|
180
|
-
# # Adding a field to an open struct adds it to the instance
|
181
|
-
# myStruct = SuperStruct.open(:alpha)
|
182
|
-
# x = myStruct.new
|
183
|
-
# x.beta = 5
|
184
|
-
#
|
185
|
-
# # Adding a field to an open struct adds it to the class also
|
186
|
-
# myStruct = SuperStruct.open(:alpha)
|
187
|
-
# x = myStruct.new
|
188
|
-
# x.beta = 5
|
189
|
-
#
|
190
|
-
# # An array passed to SuperStruct.new need not be starred
|
191
|
-
# myStruct = SuperStruct.new(%w[alpha beta gamma])
|
192
|
-
# x = myStruct.new
|
193
|
-
#
|
194
|
-
# # A hash passed to #set will set multiple values at once
|
195
|
-
# myStruct = SuperStruct.new(%w[alpha beta gamma])
|
196
|
-
# x = myStruct.new
|
197
|
-
# hash = {"alpha"=>234,"beta"=>345,"gamma"=>456}
|
198
|
-
# x.set(hash)
|
199
|
-
#
|
200
|
-
# # ||= works properly
|
201
|
-
# x = SuperStruct.open.new
|
202
|
-
# x.foo ||= 333
|
203
|
-
# x.bar = x.bar || 444
|
204
|
-
#
|
205
|
-
# # attr_tester will create a ?-method
|
206
|
-
# myStruct = SuperStruct.new(:alive)
|
207
|
-
# myStruct.attr_tester :alive
|
208
|
-
# x = myStruct.new(true)
|
209
|
-
# x.alive? # true
|
210
|
-
#
|
211
|
-
#
|
212
|
-
# == Author(s)
|
213
|
-
#
|
214
|
-
# * Hal Fulton
|
215
|
-
#
|
216
|
-
|
217
|
-
class SuperStruct
|
218
|
-
|
219
|
-
def SuperStruct.new(*args)
|
220
|
-
@table = []
|
221
|
-
@setsyms = [] # Setter symbols
|
222
|
-
klass = Class.new
|
223
|
-
if (args.size == 1) && (args[0].is_a? Array)
|
224
|
-
args = args[0]
|
225
|
-
end
|
226
|
-
strs = args.map {|x| x.to_s }
|
227
|
-
args.each_with_index do |k,i|
|
228
|
-
case
|
229
|
-
when (! [String,Symbol].include? k.class)
|
230
|
-
raise ArgumentError, "Need a String or Symbol"
|
231
|
-
when (strs[i] !~ /[_a-zA-Z][_a-zA-Z0-9]*/)
|
232
|
-
raise ArgumentError, "Illegal character"
|
233
|
-
end
|
234
|
-
k = k.intern if k.is_a? String
|
235
|
-
@table << k
|
236
|
-
@setsyms << (k.to_s + "=").intern
|
237
|
-
klass.instance_eval { attr_accessor k }
|
238
|
-
end
|
239
|
-
|
240
|
-
setsyms = @setsyms
|
241
|
-
table = @table
|
242
|
-
vals = @vals
|
243
|
-
klass.class_eval do
|
244
|
-
attr_reader :singleton
|
245
|
-
define_method(:initialize) do |*vals|
|
246
|
-
n = vals.size
|
247
|
-
m = table.size
|
248
|
-
case
|
249
|
-
when n < m
|
250
|
-
# raise ArgumentError, "Too few arguments (#{n} for #{m})"
|
251
|
-
# Never mind... extra variables will just be nil
|
252
|
-
when n > m
|
253
|
-
raise ArgumentError, "Too many arguments (#{n} for #{m})"
|
254
|
-
end
|
255
|
-
setsyms.each_with_index do |var,i|
|
256
|
-
self.send(var,vals[i])
|
257
|
-
end
|
258
|
-
end
|
259
|
-
define_method(:pretty_print) do |q| # pp.rb support
|
260
|
-
q.object_group(self) do
|
261
|
-
q.seplist(self.members, proc { q.text "," }) do |member|
|
262
|
-
# self.members.each do |member|
|
263
|
-
# q.text "," # unless q.first?
|
264
|
-
q.breakable
|
265
|
-
q.text member.to_s
|
266
|
-
q.text '='
|
267
|
-
q.group(1) do
|
268
|
-
q.breakable ''
|
269
|
-
q.pp self[member]
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
define_method(:inspect) do
|
275
|
-
str = "#<#{self.class}:"
|
276
|
-
table.each {|item| str << " #{item}=#{self.send(item)}" }
|
277
|
-
str + ">"
|
278
|
-
end
|
279
|
-
define_method(:[]) do |*index|
|
280
|
-
case index.map {|x| x.class }
|
281
|
-
when [Fixnum]
|
282
|
-
self.send(table[*index])
|
283
|
-
when [Fixnum,Fixnum], [Range]
|
284
|
-
table[*index].map {|x| self.send(x)}
|
285
|
-
when [String]
|
286
|
-
self.send(index[0].intern)
|
287
|
-
when [Symbol]
|
288
|
-
self.send(index[0])
|
289
|
-
else
|
290
|
-
raise ArgumentError,"Illegal index"
|
291
|
-
end
|
292
|
-
end
|
293
|
-
define_method(:[]=) do |*index|
|
294
|
-
value = index[-1]
|
295
|
-
index = index[0..-2]
|
296
|
-
case index.map {|x| x.class }
|
297
|
-
when [Fixnum]
|
298
|
-
self.send(table[*index])
|
299
|
-
when [Fixnum,Fixnum], [Range]
|
300
|
-
setsyms[*index].map {|x| self.send(x,value) }
|
301
|
-
when [String]
|
302
|
-
self.send(index[0].intern,value)
|
303
|
-
when [Symbol]
|
304
|
-
self.send(index[0],value)
|
305
|
-
else
|
306
|
-
raise ArgumentError,"Illegal index"
|
307
|
-
end
|
308
|
-
end
|
309
|
-
define_method(:to_a) { table.map {|x| eval("@"+x.to_s) } }
|
310
|
-
define_method(:to_ary) { to_a }
|
311
|
-
define_method(:members) { table.map {|x| x.to_s } }
|
312
|
-
define_method(:to_struct) do
|
313
|
-
mems = table
|
314
|
-
Struct.new("TEMP",*mems)
|
315
|
-
# Struct::TEMP.new(*vals) # Why doesn't this work??
|
316
|
-
data = mems.map {|x| self.send(x) }
|
317
|
-
Struct::TEMP.new(*data)
|
318
|
-
end
|
319
|
-
define_method(:to_hash) do
|
320
|
-
hash = {}
|
321
|
-
table.each do |mem|
|
322
|
-
mem = mem.to_s
|
323
|
-
hash.update(mem => self.send(mem))
|
324
|
-
end
|
325
|
-
hash
|
326
|
-
end
|
327
|
-
define_method(:set) {|h| h.each_pair {|k,v| send(k.to_s+"=",v) } }
|
328
|
-
|
329
|
-
# Class methods...
|
330
|
-
|
331
|
-
@singleton = class << self
|
332
|
-
self
|
333
|
-
end
|
334
|
-
|
335
|
-
@singleton.instance_eval do
|
336
|
-
define_method(:members) do
|
337
|
-
table.map {|x| x.to_s }
|
338
|
-
end
|
339
|
-
me = self
|
340
|
-
define_method(:attr_tester) do |*syms|
|
341
|
-
syms.each {|sym| alias_method(sym.to_s+"?",sym) }
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
end
|
346
|
-
klass
|
347
|
-
end
|
348
|
-
|
349
|
-
|
350
|
-
def SuperStruct.open(*args)
|
351
|
-
klass = SuperStruct.new(*args)
|
352
|
-
table = @table
|
353
|
-
setsyms = @setsyms
|
354
|
-
table = @table
|
355
|
-
klass.class_eval do
|
356
|
-
define_method(:method_missing) do |meth, *args|
|
357
|
-
mname = meth.id2name
|
358
|
-
if mname =~ /=$/
|
359
|
-
getter = mname.chop
|
360
|
-
setter = mname
|
361
|
-
elsif mname =~ /\?$/
|
362
|
-
raise NoMethodError # ?-methods are not created automatically
|
363
|
-
else
|
364
|
-
getter = mname
|
365
|
-
setter = mname + "="
|
366
|
-
end
|
367
|
-
gsym = getter.intern
|
368
|
-
ssym = setter.intern
|
369
|
-
ivar = "@" + getter
|
370
|
-
setsyms << setter
|
371
|
-
table << getter
|
372
|
-
len = args.length
|
373
|
-
if mname == getter
|
374
|
-
klass.class_eval do # getter
|
375
|
-
define_method(getter) do
|
376
|
-
instance_variable_get(ivar)
|
377
|
-
end
|
378
|
-
end
|
379
|
-
else
|
380
|
-
klass.class_eval do # setter
|
381
|
-
define_method(setter) do |*args|
|
382
|
-
if len != 1
|
383
|
-
raise ArgumentError, "Wrong # of arguments (#{len} for 1)", caller(1)
|
384
|
-
end
|
385
|
-
instance_variable_set(ivar,args[0])
|
386
|
-
instance_variable_get(ivar)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
if mname == setter
|
391
|
-
self.send(setter,*args)
|
392
|
-
else
|
393
|
-
if len == 0
|
394
|
-
self.send(getter)
|
395
|
-
else
|
396
|
-
raise NoMethodError, "Undefined method '#{mname}' for #{self}", caller(1)
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
end
|
401
|
-
klass
|
402
|
-
end
|
403
|
-
|
404
|
-
end
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
# _____ _
|
409
|
-
# |_ _|__ ___| |_
|
410
|
-
# | |/ _ \/ __| __|
|
411
|
-
# | | __/\__ \ |_
|
412
|
-
# |_|\___||___/\__|
|
413
|
-
#
|
414
|
-
|
415
|
-
=begin testing
|
416
|
-
|
417
|
-
#
|
418
|
-
# SuperStruct test code
|
419
|
-
# Hal Fulton
|
420
|
-
# Version 1.0.1 (in sync with library code)
|
421
|
-
# License: The Ruby License
|
422
|
-
#
|
423
|
-
|
424
|
-
require "test/unit"
|
425
|
-
|
426
|
-
class Tester < Test::Unit::TestCase
|
427
|
-
|
428
|
-
def test001
|
429
|
-
# Must pass in String or Symbol
|
430
|
-
assert_raises(ArgumentError) { SuperStruct.new(0) }
|
431
|
-
end
|
432
|
-
|
433
|
-
def test002
|
434
|
-
# Must pass in valid name(s)
|
435
|
-
assert_raises(ArgumentError) { SuperStruct.new("###") }
|
436
|
-
end
|
437
|
-
|
438
|
-
def test003
|
439
|
-
# Can't assign to nonexistent fields
|
440
|
-
myStruct = SuperStruct.new
|
441
|
-
assert_raises(ArgumentError) { myStruct.new(345) }
|
442
|
-
end
|
443
|
-
|
444
|
-
def test004
|
445
|
-
# Need not assign to existing fields (default to nil)
|
446
|
-
myStruct = SuperStruct.new(:alpha)
|
447
|
-
assert_nothing_raised(ArgumentError) { myStruct.new }
|
448
|
-
end
|
449
|
-
|
450
|
-
def test005
|
451
|
-
# A value assigned at construction may be retrieved
|
452
|
-
myStruct = SuperStruct.new(:alpha)
|
453
|
-
x = myStruct.new(234)
|
454
|
-
assert(x.alpha == 234)
|
455
|
-
end
|
456
|
-
|
457
|
-
def test006
|
458
|
-
# Unassigned fields are nil
|
459
|
-
myStruct = SuperStruct.new(:alpha,:beta)
|
460
|
-
x = myStruct.new(234)
|
461
|
-
assert(x.beta == nil)
|
462
|
-
end
|
463
|
-
|
464
|
-
def test007
|
465
|
-
# An open structure still may not construct with nonexistent fields
|
466
|
-
myStruct = SuperStruct.open
|
467
|
-
assert_raises(ArgumentError) { x = myStruct.new(234) }
|
468
|
-
end
|
469
|
-
|
470
|
-
def test008
|
471
|
-
# An open structure may assign fields not previously existing
|
472
|
-
myStruct = SuperStruct.open
|
473
|
-
x = myStruct.new
|
474
|
-
assert_nothing_raised { x.foobar = 123 }
|
475
|
-
end
|
476
|
-
|
477
|
-
def test009
|
478
|
-
# A field assigned to an open struct after its construction may be retrieved
|
479
|
-
myStruct = SuperStruct.open
|
480
|
-
x = myStruct.new
|
481
|
-
x.foobar = 123
|
482
|
-
assert(x.foobar == 123)
|
483
|
-
end
|
484
|
-
|
485
|
-
def test010
|
486
|
-
# The act of retrieving a nonexistent field from an open struct will
|
487
|
-
# create that field
|
488
|
-
myStruct = SuperStruct.open
|
489
|
-
x = myStruct.new
|
490
|
-
assert_nothing_raised { y = x.foobar }
|
491
|
-
end
|
492
|
-
|
493
|
-
def test011
|
494
|
-
# A field (in an open struct) that is unassigned will be nil
|
495
|
-
myStruct = SuperStruct.open
|
496
|
-
x = myStruct.new
|
497
|
-
y = x.foobar
|
498
|
-
assert(y == nil)
|
499
|
-
end
|
500
|
-
|
501
|
-
def test012
|
502
|
-
# A struct created with new rather than open cannot reference nonexistent
|
503
|
-
# fields
|
504
|
-
myStruct = SuperStruct.new
|
505
|
-
x = myStruct.new
|
506
|
-
assert_raises(NoMethodError) { y = x.foobar }
|
507
|
-
end
|
508
|
-
|
509
|
-
def test013
|
510
|
-
# Adding a field to a struct will create a writer and reader for that field
|
511
|
-
myStruct = SuperStruct.new(:alpha)
|
512
|
-
x = myStruct.new
|
513
|
-
x.send(:alpha=,1)
|
514
|
-
assert(x.alpha == 1)
|
515
|
-
end
|
516
|
-
|
517
|
-
def test014
|
518
|
-
# Only a single value may be passed to a writer (for code coverage)
|
519
|
-
myStruct = SuperStruct.new(:alpha)
|
520
|
-
x = myStruct.new
|
521
|
-
assert_raises(ArgumentError) { x.send(:alpha=,1,2) }
|
522
|
-
end
|
523
|
-
|
524
|
-
def test015
|
525
|
-
# An open struct will also create a writer and a reader together
|
526
|
-
myStruct = SuperStruct.open
|
527
|
-
x = myStruct.new
|
528
|
-
x.send(:alpha=,1)
|
529
|
-
assert(x.alpha == 1)
|
530
|
-
end
|
531
|
-
|
532
|
-
def test016
|
533
|
-
# Only a single value may be passed to a writer (for code coverage)
|
534
|
-
myStruct = SuperStruct.open
|
535
|
-
x = myStruct.new
|
536
|
-
assert_raises(ArgumentError) { x.send(:alpha=,1,2) }
|
537
|
-
end
|
538
|
-
|
539
|
-
def test017
|
540
|
-
# A field has a real writer and reader corresponding to it
|
541
|
-
myStruct = SuperStruct.new(:alpha)
|
542
|
-
x = myStruct.new
|
543
|
-
assert(myStruct.instance_methods.include?("alpha"))
|
544
|
-
assert(myStruct.instance_methods.include?("alpha="))
|
545
|
-
end
|
546
|
-
|
547
|
-
def test018
|
548
|
-
# Creating a field by retrieval in an open struct will NOT create a writer
|
549
|
-
# (This behavior has changed!)
|
550
|
-
myStruct = SuperStruct.open
|
551
|
-
x = myStruct.new
|
552
|
-
y = x.alpha
|
553
|
-
assert(myStruct.instance_methods.include?("alpha"))
|
554
|
-
assert(!myStruct.instance_methods.include?("alpha="))
|
555
|
-
end
|
556
|
-
|
557
|
-
def test019
|
558
|
-
# Creating a field by writing in an open struct will NOT create a reader
|
559
|
-
# (This behavior has changed!)
|
560
|
-
myStruct = SuperStruct.open
|
561
|
-
x = myStruct.new
|
562
|
-
x.alpha = 5
|
563
|
-
assert(myStruct.instance_methods.include?("alpha="))
|
564
|
-
assert(!myStruct.instance_methods.include?("alpha"))
|
565
|
-
end
|
566
|
-
|
567
|
-
def test020
|
568
|
-
# A string will work as well as a symbol
|
569
|
-
myStruct = SuperStruct.new("alpha")
|
570
|
-
x = myStruct.new
|
571
|
-
assert(myStruct.instance_methods.include?("alpha"))
|
572
|
-
assert(myStruct.instance_methods.include?("alpha="))
|
573
|
-
end
|
574
|
-
|
575
|
-
def test021
|
576
|
-
# to_a will return an array of values
|
577
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
578
|
-
x = myStruct.new(7,8,9)
|
579
|
-
assert(x.to_a == [7,8,9])
|
580
|
-
end
|
581
|
-
|
582
|
-
def test022
|
583
|
-
# Instance method 'members' will return a list of members (as strings)
|
584
|
-
myStruct = SuperStruct.new(:alpha,"beta")
|
585
|
-
x = myStruct.new
|
586
|
-
assert_equal(["alpha","beta"],x.members)
|
587
|
-
end
|
588
|
-
|
589
|
-
def test023
|
590
|
-
# Class method 'members' will return a list of members (as strings)
|
591
|
-
myStruct = SuperStruct.new(:alpha,"beta")
|
592
|
-
assert_equal(["alpha","beta"],myStruct.members)
|
593
|
-
end
|
594
|
-
|
595
|
-
def test024
|
596
|
-
# to_ary will allow a struct to be treated like an array in
|
597
|
-
# multiple assignment
|
598
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
599
|
-
x = myStruct.new(7,8,9)
|
600
|
-
a,b,c = x
|
601
|
-
assert(b == 8)
|
602
|
-
end
|
603
|
-
|
604
|
-
def aux025(*arr) # Just used in test 25
|
605
|
-
arr[1]
|
606
|
-
end
|
607
|
-
|
608
|
-
def test025
|
609
|
-
# to_ary will allow a struct to be treated like an array in
|
610
|
-
# passed parameters
|
611
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
612
|
-
x = myStruct.new(7,8,9)
|
613
|
-
b = aux025(*x)
|
614
|
-
assert(b == 8)
|
615
|
-
end
|
616
|
-
|
617
|
-
def test026
|
618
|
-
# to_hash will return a hash with fields as keys
|
619
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
620
|
-
x = myStruct.new(7,8,9)
|
621
|
-
h = x.to_hash
|
622
|
-
assert_equal({"alpha"=>7,"beta"=>8,"gamma"=>9},h)
|
623
|
-
end
|
624
|
-
|
625
|
-
def test027
|
626
|
-
# A field name (String) may be used in a hash-like notation
|
627
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
628
|
-
x = myStruct.new(7,8,9)
|
629
|
-
y = x["beta"]
|
630
|
-
assert(8,y)
|
631
|
-
end
|
632
|
-
|
633
|
-
def test028
|
634
|
-
# A field name (Symbol) may be used in a hash-like notation
|
635
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
636
|
-
x = myStruct.new(7,8,9)
|
637
|
-
y = x[:beta]
|
638
|
-
assert(8,y)
|
639
|
-
end
|
640
|
-
|
641
|
-
def test029
|
642
|
-
# [offset,length] may be used as for arrays
|
643
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
644
|
-
x = myStruct.new(7,8,9)
|
645
|
-
y = x[0,2]
|
646
|
-
assert([7,8],y)
|
647
|
-
end
|
648
|
-
|
649
|
-
def test030
|
650
|
-
# Ranges may be used as for arrays
|
651
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
652
|
-
x = myStruct.new(7,8,9)
|
653
|
-
y = x[1..2]
|
654
|
-
assert([8,9],y)
|
655
|
-
end
|
656
|
-
|
657
|
-
def test031
|
658
|
-
# Adding a field to an open struct adds it to the instance
|
659
|
-
myStruct = SuperStruct.open(:alpha)
|
660
|
-
x = myStruct.new
|
661
|
-
x.beta = 5
|
662
|
-
assert_equal(["alpha","beta"],x.members)
|
663
|
-
end
|
664
|
-
|
665
|
-
def test032
|
666
|
-
# Adding a field to an open struct adds it to the class also
|
667
|
-
myStruct = SuperStruct.open(:alpha)
|
668
|
-
x = myStruct.new
|
669
|
-
x.beta = 5
|
670
|
-
assert_equal(["alpha","beta"],myStruct.members)
|
671
|
-
end
|
672
|
-
|
673
|
-
def test033
|
674
|
-
# An array passed to SuperStruct.new need not be starred
|
675
|
-
myStruct = SuperStruct.new(%w[alpha beta gamma])
|
676
|
-
x = myStruct.new
|
677
|
-
assert_equal(%w[alpha beta gamma],x.members)
|
678
|
-
end
|
679
|
-
|
680
|
-
def xtest034
|
681
|
-
# A hash passed to SuperStruct.new will initialize the values
|
682
|
-
# (but order will not be predictable!)
|
683
|
-
assert false, "Not implemented yet."
|
684
|
-
end
|
685
|
-
|
686
|
-
def test035
|
687
|
-
# A hash passed to #set will set multiple values at once
|
688
|
-
myStruct = SuperStruct.new(%w[alpha beta gamma])
|
689
|
-
x = myStruct.new
|
690
|
-
hash = {"alpha"=>234,"beta"=>345,"gamma"=>456}
|
691
|
-
x.set(hash)
|
692
|
-
assert_equal([234,345,456], x.to_a)
|
693
|
-
end
|
694
|
-
|
695
|
-
def test036
|
696
|
-
# Make sure ||= works properly
|
697
|
-
x = SuperStruct.open.new
|
698
|
-
x.foo ||= 333
|
699
|
-
x.bar = x.bar || 444
|
700
|
-
assert_equal(333,x.foo)
|
701
|
-
assert_equal(444,x.bar)
|
702
|
-
end
|
703
|
-
|
704
|
-
def test037
|
705
|
-
# A simple array index works ok
|
706
|
-
myStruct = SuperStruct.new("alpha","beta","gamma")
|
707
|
-
x = myStruct.new(7,8,9)
|
708
|
-
assert_equal(7,x[0])
|
709
|
-
assert_equal(8,x[1])
|
710
|
-
assert_equal(9,x[2])
|
711
|
-
end
|
712
|
-
|
713
|
-
def test038
|
714
|
-
# attr_tester will create a ?-method
|
715
|
-
klass = SuperStruct.new(:alpha,:beta,:gamma)
|
716
|
-
klass.attr_tester :alpha, :gamma
|
717
|
-
x = klass.new(22,33,nil)
|
718
|
-
assert(x.alpha?)
|
719
|
-
assert_raises(NoMethodError) { x.beta? }
|
720
|
-
assert(! x.gamma?)
|
721
|
-
end
|
722
|
-
|
723
|
-
def test039
|
724
|
-
# attr_tester works with open() (?-methods not created)
|
725
|
-
klass = SuperStruct.open(:alpha,:beta,:gamma)
|
726
|
-
klass.attr_tester :alpha, :gamma
|
727
|
-
x = klass.new(22,33,nil)
|
728
|
-
assert(x.alpha?)
|
729
|
-
assert_raises(NoMethodError) { x.beta? } # ?-methods are not automatic
|
730
|
-
assert(! x.gamma?)
|
731
|
-
end
|
732
|
-
|
733
|
-
end
|
734
|
-
|
735
|
-
=end
|