facets 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -3
- data/ProjectInfo +5 -2
- data/conf/facets/noauto +11 -11
- data/lib/facet/aspects.rb +1 -0
- data/lib/facet/float/round_off.rb +1 -0
- data/lib/facet/kernel/instance.rb +1 -0
- data/lib/facet/kernel/pp_exception.rb +1 -0
- data/lib/facet/module/cattr.rb +1 -0
- data/lib/facet/module/on_included.rb +1 -0
- data/lib/facet/nilclass/blank.rb +1 -0
- data/lib/facet/numeric/approx.rb +1 -0
- data/lib/facet/ostruct/instance.rb +1 -0
- data/lib/facets.rb +0 -1
- data/lib/facets/core/enumerable/every.rb +1 -5
- data/lib/facets/core/float.rb +1 -0
- data/lib/facets/core/float/approx.rb +2 -42
- data/lib/facets/core/float/round_at.rb +2 -1
- data/lib/facets/core/float/round_off.rb +8 -0
- data/lib/facets/core/float/round_to.rb +2 -1
- data/lib/facets/core/gem.rb +0 -3
- data/lib/facets/core/hash/inverse.rb +3 -1
- data/lib/facets/core/inflect.rb +3 -0
- data/lib/facets/core/kernel.rb +2 -2
- data/lib/facets/core/kernel/{__meta__.rb → instance.rb} +10 -9
- data/lib/facets/core/kernel/pp_exception.rb +17 -0
- data/lib/facets/core/module.rb +2 -0
- data/lib/facets/core/module/attr.rb +4 -1
- data/lib/facets/core/module/basename.rb +12 -1
- data/lib/facets/core/module/cattr.rb +180 -0
- data/lib/facets/core/module/cattr_accessor.rb +2 -141
- data/lib/facets/core/module/cattr_reader.rb +1 -1
- data/lib/facets/core/module/cattr_writer.rb +1 -1
- data/lib/facets/core/module/on_included.rb +48 -0
- data/lib/facets/core/module/wrap_method.rb +7 -2
- data/lib/facets/core/nilclass.rb +1 -1
- data/lib/facets/core/nilclass/{to_f.rb → blank.rb} +6 -6
- data/lib/facets/core/nilclass/op_cmp.rb +11 -0
- data/lib/facets/core/nilclass/succ.rb +5 -0
- data/lib/facets/core/numeric.rb +1 -0
- data/lib/facets/core/numeric/approx.rb +34 -0
- data/lib/facets/core/ostruct/__update__.rb +2 -2
- data/lib/facets/core/ostruct/instance.rb +37 -0
- data/lib/facets/core/string/modulize.rb +1 -1
- data/lib/facets/more/consoleapp.rb +27 -16
- data/lib/facets/more/crypt.rb +8 -4
- data/lib/facets/more/elementor.rb +104 -0
- data/lib/facets/more/expirable.rb +5 -0
- data/lib/facets/more/nilcomparable.rb +88 -31
- data/lib/facets/more/overload.rb +1 -1
- data/lib/facets/more/typecast.rb +12 -3
- data/test/FIXTURE/filelist/testfile.txt +0 -0
- data/test/FIXTURE/filelist/testfile2.txt +0 -0
- data/test/lib/{facet → facets/core}/array/test_at_rand.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_delete_unless.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_delete_values.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_delete_values_at.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_first.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_head.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_last_index.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_merge.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_mid.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_middle.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_op_fetch.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_op_store.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_pick.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_pos.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_pull.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_rand_index.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_rand_subset.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_range.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_rotate.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_select.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_shuffle.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_slap.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_thru.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_to_b.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_to_h.rb +3 -3
- data/test/lib/{facet → facets/core}/array/test_to_hash.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/self/test_of_caller.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test___LINE__.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_call_stack.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_called.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_caller.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_defined.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_eval.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_local_variables.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_method_name.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_op_fetch.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_op_store.rb +3 -3
- data/test/lib/{facet → facets/core}/binding/test_self.rb +3 -3
- data/test/lib/{facet → facets/core}/class/test_descendents.rb +3 -3
- data/test/lib/{facet → facets/core}/class/test_method_name.rb +3 -3
- data/test/lib/{facet → facets/core}/class/test_remove_descendents.rb +3 -3
- data/test/lib/{facet → facets/core}/class/test_unix_path.rb +3 -3
- data/test/lib/{facet → facets/core}/comparable/test_at_least.rb +3 -3
- data/test/lib/{facet → facets/core}/comparable/test_clip.rb +3 -3
- data/test/lib/{facet → facets/core}/comparable/test_cmp.rb +3 -3
- data/test/lib/{facet → facets/core}/continuation/self/test_create.rb +3 -3
- data/test/lib/{facet → facets/core}/date/test_days_in_month.rb +3 -3
- data/test/lib/{facet → facets/core}/date/test_days_of_month.rb +3 -3
- data/test/lib/{facet → facets/core}/date/test_stamp.rb +3 -3
- data/test/lib/{facet → facets/core}/date/test_to_date.rb +3 -3
- data/test/lib/{facet → facets/core}/date/test_to_s.rb +3 -3
- data/test/lib/{facet → facets/core}/date/test_to_time.rb +3 -3
- data/test/lib/{facet → facets/core}/dir/self/test_ancestor.rb +3 -3
- data/test/lib/{facet → facets/core}/dir/self/test_ascend.rb +3 -3
- data/test/lib/{facet → facets/core}/dir/self/test_ls_r.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/self/test_combinations.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/self/test_cross.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_collect_with_index.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_commonality.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_compact_collect.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_cross.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_each_combination.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_each_pair.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_each_slice.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_each_unique_pair.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_entropy.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_every.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_ew.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_filter_collect.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_find_collisions.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_frequency.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_graph.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_ideal_entropy.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_none.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_occur.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_one.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_op_pow.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_partition_by.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_permute.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_probability.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_to_h.rb +3 -3
- data/test/lib/{facet → facets/core}/enumerable/test_uniq_by.rb +3 -3
- data/test/lib/{facet → facets/core}/file/self/test_create.rb +3 -3
- data/test/lib/{facet → facets/core}/file/self/test_open_as_string.rb +3 -3
- data/test/lib/{facet → facets/core}/file/self/test_read_list.rb +3 -3
- data/test/lib/{facet → facets/core}/file/self/test_sanitize.rb +3 -3
- data/test/lib/{facet → facets/core}/file/self/test_split_all.rb +3 -3
- data/test/lib/{facet → facets/core}/fileutils/test_wc.rb +3 -3
- data/test/lib/{facet → facets/core}/fileutils/test_which.rb +3 -3
- data/test/lib/{facet → facets/core}/float/test_approx.rb +3 -3
- data/test/lib/{facet → facets/core}/float/test_round_at.rb +3 -3
- data/test/lib/{facet → facets/core}/float/test_round_to.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/self/test_zipnew.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_alias.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_assert_has_keys.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_assert_has_only_keys.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_at.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_collate.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_each.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_each_with_index.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_each_with_key.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_graph.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_has_keys.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_has_only_keys.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_inverse.rb +6 -4
- data/test/lib/{facet → facets/core}/hash/test_keys_to_s.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_keys_to_sym.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_op_fetch.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_op_lshift.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_rand_key.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_rand_pair.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_rand_value.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_replace_each.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_shuffle.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_slice.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_swap.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_swapkey.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_to_h.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_to_ostruct.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_to_ostruct_recurse.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_traverse.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_update_each.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_update_keys.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_update_values.rb +3 -3
- data/test/lib/{facet → facets/core}/hash/test_weave.rb +3 -3
- data/test/lib/{facet → facets/core}/integer/test_factorial.rb +3 -3
- data/test/lib/{facet → facets/core}/integer/test_multiple.rb +3 -3
- data/test/lib/{facet → facets/core}/integer/test_ordinal.rb +3 -3
- data/test/lib/{facet → facets/core}/integer/test_times_collect.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test___class__.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_as.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_assign_from.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_assign_with.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_bool.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_bug.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_call_stack.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_called.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_constant.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_copy.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_deep_copy.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_demo.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_fn.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_generate_method_name.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_get_by_id.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_here.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_in.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_maybe.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_metaclass.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_method.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_method_name.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_methods.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_new.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_object_class.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_object_hexid.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_require_all.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_require_esc.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_require_facet.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_resc.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_returning.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_send_as.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_set_from.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_set_with.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_silently.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_singleton.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_superior.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_supermethod.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_this.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_to_b.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_to_bool.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_uri.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_val.rb +3 -3
- data/test/lib/{facet → facets/core}/kernel/test_with_accessor.rb +3 -3
- data/test/lib/{facet → facets/core}/matchdata/test_match.rb +3 -3
- data/test/lib/{facet → facets/core}/matchdata/test_matchtree.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_abstract.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_alias_module_function.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_ancestor.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_basename.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_by_name.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_cattr_accessor.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_clone_using.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_dirname.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_equate_on.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_generate_instance_method_name.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_include_as.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_initializer.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_instance_methods.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_integrate.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_memoize.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_modspace.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_namespace.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_nesting.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_redef.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_redefine_method.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_redirect.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_redirect_method.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_remove.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_rename.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_rename_method.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_revisal.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_shadow_method.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_sort_on.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_undef.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_wrap.rb +3 -3
- data/test/lib/{facet → facets/core}/module/test_wrap_method.rb +3 -3
- data/test/lib/{facet → facets/core}/nilclass/test_empty.rb +3 -3
- data/test/lib/{facet → facets/core}/nilclass/test_include.rb +3 -3
- data/test/lib/{facet → facets/core}/nilclass/test_op_fetch.rb +3 -3
- data/test/lib/{facet → facets/core}/nilclass/test_size.rb +3 -3
- data/test/lib/{facet → facets/core}/nilclass/test_to_f.rb +3 -3
- data/test/lib/{facet → facets/core}/nilclass/test_to_h.rb +3 -3
- data/test/lib/{facet → facets/core}/numeric/test_ceil_multiple.rb +3 -3
- data/test/lib/{facet → facets/core}/numeric/test_succ.rb +3 -3
- data/test/lib/{facet → facets/core}/numeric/test_to_b.rb +3 -3
- data/test/lib/{facet → facets/core}/ostruct/test___merge__.rb +3 -3
- data/test/lib/{facet → facets/core}/ostruct/test___update__.rb +3 -3
- data/test/lib/{facet → facets/core}/ostruct/test_op_fetch.rb +3 -3
- data/test/lib/{facet → facets/core}/ostruct/test_op_store.rb +3 -3
- data/test/lib/{facet → facets/core}/proc/test_compose.rb +3 -3
- data/test/lib/{facet → facets/core}/proc/test_to_method.rb +3 -3
- data/test/lib/{facet → facets/core}/range/test_to_r.rb +3 -3
- data/test/lib/{facet → facets/core}/range/test_to_range.rb +3 -3
- data/test/lib/{facet → facets/core}/range/test_umbrella.rb +3 -3
- data/test/lib/{facet → facets/core}/range/test_within.rb +3 -3
- data/test/lib/{facet → facets/core}/regexp/test_arity.rb +3 -3
- data/test/lib/{facet → facets/core}/regexp/test_to_re.rb +3 -3
- data/test/lib/{facet → facets/core}/regexp/test_to_regexp.rb +3 -3
- data/test/lib/{facet → facets/core}/string/self/test_interpolate.rb +3 -3
- data/test/lib/{facet → facets/core}/string/self/test_patterns.rb +3 -3
- data/test/lib/{facet → facets/core}/string/self/test_rand_letter.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_align_center.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_at_rand.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_basename.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_blank.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_bracket.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_camelcase.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_camelize.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_capitalized.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_chars.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_cmp.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_demodulize.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_downcase.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_dresner.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_each_char.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_each_word.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_first.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_fold.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_frequency.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_humanize.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_indent.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_index_all.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_last.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_line_wrap.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_lines.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_lowercase.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_margin.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_methodize.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_modulize.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_mscan.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_natcmp.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_nchar.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_pathize.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_pop.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_probability.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_push.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_quote.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_rand_byte.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_rand_index.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_range.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_range_all.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_range_of_line.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_regesc.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_shatter.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_shift.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_shuffle.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_similarity.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_singular.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_slap.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_soundex.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_succ.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_a.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_arr.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_b.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_const.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_date.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_proc.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_re.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_to_time.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_unix_crypt.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_unpack.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_unshift.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_upcase.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_whitespace.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_word_filter.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_word_wrap.rb +3 -3
- data/test/lib/{facet → facets/core}/string/test_words.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_camelcase.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_camelize.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_capitalize.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_capitalized.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_downcase.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_not.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_pad.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_succ.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_to_const.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_to_proc.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_to_str.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_underscore.rb +3 -3
- data/test/lib/{facet → facets/core}/symbol/test_upcase.rb +3 -3
- data/test/lib/{facet → facets/core}/time/test_change.rb +3 -3
- data/test/lib/{facet → facets/core}/time/test_elapse.rb +3 -3
- data/test/lib/{facet → facets/core}/time/test_stamp.rb +3 -3
- data/test/lib/{facet → facets/core}/time/test_to_date.rb +3 -3
- data/test/lib/{facet → facets/core}/time/test_to_s.rb +3 -3
- data/test/lib/{facet → facets/core}/time/test_to_time.rb +3 -3
- data/test/lib/facets/more/test_annotation.rb +217 -0
- data/test/lib/facets/more/test_ansicode.rb +36 -0
- data/test/lib/facets/more/test_association.rb +46 -0
- data/test/lib/facets/more/test_bbcode.rb +34 -0
- data/test/lib/facets/more/test_bitmask.rb +47 -0
- data/test/lib/facets/more/test_bytes.rb +84 -0
- data/test/lib/facets/more/test_classinherit.rb +65 -0
- data/test/lib/facets/more/test_classmethods.rb +65 -0
- data/test/lib/facets/more/test_coroutine.rb +60 -0
- data/test/lib/facets/more/test_crypt.rb +46 -0
- data/test/lib/facets/more/test_dictionary.rb +97 -0
- data/test/lib/facets/more/test_enumerablepass.rb +86 -0
- data/test/lib/facets/more/test_floatstring.rb +36 -0
- data/test/lib/facets/more/test_functor.rb +39 -0
- data/test/lib/facets/more/test_inheritor.rb +155 -0
- data/test/lib/facets/more/test_interval.rb +119 -0
- data/test/lib/facets/more/test_lisp.rb +47 -0
- data/test/lib/facets/more/test_lisp_format.rb +37 -0
- data/test/lib/facets/more/test_lrucache.rb +25 -0
- data/test/lib/facets/more/test_mathconstants.rb +18 -0
- data/test/lib/facets/more/test_methodprobe.rb +53 -0
- data/test/lib/facets/more/test_multipliers.rb +114 -0
- data/test/lib/facets/more/test_multiton.rb +200 -0
- data/test/lib/facets/more/test_nackclass.rb +45 -0
- data/test/lib/facets/more/test_nilcomparable.rb +43 -0
- data/test/lib/facets/more/test_openobject.rb +66 -0
- data/test/lib/facets/more/test_overload.rb +54 -0
- data/test/lib/facets/more/test_paramix.rb +100 -0
- data/test/lib/facets/more/test_preinitialize.rb +49 -0
- data/test/lib/facets/more/test_promoteself.rb +45 -0
- data/test/lib/facets/more/test_snapshot.rb +34 -0
- data/test/lib/facets/more/test_statichash.rb +31 -0
- data/test/lib/facets/more/test_syncarray.rb +28 -0
- data/test/lib/facets/more/test_synchash.rb +28 -0
- data/test/lib/facets/more/test_tagiterator.rb +93 -0
- data/test/lib/facets/more/test_timer.rb +66 -0
- data/test/lib/facets/more/test_times.rb +73 -0
- data/test/lib/facets/more/test_tuple.rb +32 -0
- data/test/lib/facets/more/test_typecast.rb +65 -0
- data/test/lib/facets/more/test_uninheritable.rb +42 -0
- data/test/lib/facets/more/test_units.rb +104 -0
- data/test/lib/facets/more/test_yamlstruct.rb +37 -0
- metadata +416 -357
- data/lib/facet/kernel/__meta__.rb +0 -1
- data/lib/facet/kernel/meta.rb +0 -1
- data/lib/facet/nilclass/to_f.rb +0 -1
- data/lib/facets/core/kernel/meta.rb +0 -2
- data/test/lib/facet/fileutils/test_slice.rb +0 -96
data/CHANGELOG
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
= Facets Change Log
|
2
2
|
|
3
|
-
== 1.1
|
4
|
-
*
|
3
|
+
== 1.2.1
|
4
|
+
* kernel/meta has been renamed to kernel/instance
|
5
|
+
|
6
|
+
== 1.2.0
|
5
7
|
* Added zimba.tm's string/modulize, pathize and methodize.
|
6
8
|
* Added some Gem methods, self/active?, self/gemspec, self/gempath.
|
7
9
|
|
8
10
|
== 1.0.3
|
9
11
|
* A last ditch attempt to keep facets and calibre as one project.
|
10
|
-
* Last Ditch is the key term here -- it has failed.
|
11
12
|
|
12
13
|
== 1.0.2
|
13
14
|
* Added _why's Array modulo.
|
data/ProjectInfo
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
TITLE : Facets
|
4
4
|
NAME : facets
|
5
|
-
VERSION : '1.2.
|
6
|
-
DATE : '2006-03-
|
5
|
+
VERSION : '1.2.1'
|
6
|
+
DATE : '2006-03-29'
|
7
7
|
STATUS : Beta/Stable
|
8
8
|
|
9
9
|
AUTHOR : Thomas Sawyer
|
@@ -36,6 +36,9 @@ RUBYFORGE:
|
|
36
36
|
PROJECT: 'facets'
|
37
37
|
USERNAME: transami
|
38
38
|
|
39
|
+
TESTEXT:
|
40
|
+
files: 'lib/facets/**/*.rb'
|
41
|
+
|
39
42
|
RDOC:
|
40
43
|
- dir: web/doc/api/core
|
41
44
|
template: jamis
|
data/conf/facets/noauto
CHANGED
@@ -8,26 +8,26 @@
|
|
8
8
|
array/op_fetch.rb
|
9
9
|
array/op_store.rb
|
10
10
|
binding/self/of_caller.rb
|
11
|
-
date/*
|
12
|
-
fileutils/*
|
13
11
|
hash/op_fetch.rb
|
14
12
|
hash/op_store.rb
|
15
13
|
object/new.rb
|
16
|
-
|
17
|
-
|
14
|
+
numeric/succ.rb
|
15
|
+
numeric/pred.rb
|
18
16
|
string/succ.rb
|
19
17
|
string/unpack.rb
|
20
|
-
|
21
|
-
# The following will probably be certified as full-able soon.
|
22
|
-
|
23
|
-
# deprecated?
|
24
|
-
#module/attr.rb
|
18
|
+
module/attr.rb # b/c it always makes a writer
|
25
19
|
#module/attr_reader.rb
|
26
20
|
#module/attr_writer.rb
|
27
21
|
#module/attr_accessor.rb
|
28
22
|
|
29
|
-
|
30
|
-
|
23
|
+
# These classes are not automatically loaded by Ruby
|
24
|
+
# (i.e. they are part of the standard lib, not core)
|
25
|
+
|
26
|
+
date/*
|
27
|
+
fileutils/*
|
28
|
+
ostruct/*
|
29
|
+
logger/*
|
30
|
+
gem/*
|
31
31
|
|
32
32
|
# Files not included with the full feature set b/c they are potentially
|
33
33
|
# unsafe b/c they change Ruby's default behavior in a nonconvential
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/more/aspects.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/float/round_off.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/kernel/instance.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/kernel/pp_exception.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/module/cattr.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/module/on_included.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/nilclass/blank.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/numeric/approx.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/core/ostruct/instance.rb'
|
data/lib/facets.rb
CHANGED
@@ -60,7 +60,6 @@ $: << File.join( File.dirname(__FILE__), 'facets/more' )
|
|
60
60
|
# Elementary
|
61
61
|
require 'facets/core/comparable/cmp'
|
62
62
|
require 'facets/core/string/cmp'
|
63
|
-
require 'facets/core/nilclass/to_f'
|
64
63
|
require 'facets/core/nilclass/to_h'
|
65
64
|
require 'facets/core/binding/eval'
|
66
65
|
require 'facets/core/binding/self'
|
data/lib/facets/core/float.rb
CHANGED
@@ -1,42 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Float
|
4
|
-
# Determines if another number is approximately equal
|
5
|
-
# within a given _n_th degree. Defaults to 100ths
|
6
|
-
# if the degree is not specified.
|
7
|
-
def approx?( x, n=0.01 )
|
8
|
-
return(self == x) if n == 0
|
9
|
-
self.round_to(n) == x.to_f.round_to(n)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Numeric
|
14
|
-
# To properly support Float#approx?,
|
15
|
-
# Numeric must also be augmented.
|
16
|
-
def approx?(*args)
|
17
|
-
self.to_f.approx?(*args)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
# _____ _
|
23
|
-
# |_ _|__ ___| |_
|
24
|
-
# | |/ _ \/ __| __|
|
25
|
-
# | | __/\__ \ |_
|
26
|
-
# |_|\___||___/\__|
|
27
|
-
#
|
28
|
-
=begin test
|
29
|
-
|
30
|
-
require 'test/unit'
|
31
|
-
|
32
|
-
class TCFloat < Test::Unit::TestCase
|
33
|
-
|
34
|
-
def test_approx?
|
35
|
-
f = 10.006
|
36
|
-
assert( f.approx?(10.01) )
|
37
|
-
assert( f.approx?(10, 0.1) )
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
=end
|
1
|
+
# stub
|
2
|
+
require 'facets/core/numeric/approx.rb'
|
data/lib/facets/core/gem.rb
CHANGED
data/lib/facets/core/inflect.rb
CHANGED
@@ -47,6 +47,9 @@ require 'facet/string/humanize'
|
|
47
47
|
|
48
48
|
require 'facet/string/basename'
|
49
49
|
require 'facet/string/demodulize'
|
50
|
+
require 'facet/string/modulize'
|
51
|
+
require 'facet/string/methodize'
|
52
|
+
require 'facet/string/pathize'
|
50
53
|
|
51
54
|
require 'facet/string/upcase'
|
52
55
|
require 'facet/string/downcase'
|
data/lib/facets/core/kernel.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'facets/core/kernel/__DIR__'
|
2
2
|
require 'facets/core/kernel/__class__'
|
3
|
-
require 'facets/core/kernel/__meta__'
|
4
3
|
require 'facets/core/kernel/adhoc'
|
5
4
|
require 'facets/core/kernel/as'
|
6
5
|
require 'facets/core/kernel/assign_from'
|
@@ -24,12 +23,12 @@ require 'facets/core/kernel/generate_method_name'
|
|
24
23
|
require 'facets/core/kernel/get_by_id'
|
25
24
|
require 'facets/core/kernel/here'
|
26
25
|
require 'facets/core/kernel/in'
|
26
|
+
require 'facets/core/kernel/instance'
|
27
27
|
require 'facets/core/kernel/instance_assign'
|
28
28
|
require 'facets/core/kernel/instvar'
|
29
29
|
require 'facets/core/kernel/is'
|
30
30
|
require 'facets/core/kernel/maybe'
|
31
31
|
require 'facets/core/kernel/me'
|
32
|
-
require 'facets/core/kernel/meta'
|
33
32
|
require 'facets/core/kernel/metaclass'
|
34
33
|
require 'facets/core/kernel/method'
|
35
34
|
require 'facets/core/kernel/method_name'
|
@@ -41,6 +40,7 @@ require 'facets/core/kernel/object_hexid'
|
|
41
40
|
require 'facets/core/kernel/op_esc'
|
42
41
|
require 'facets/core/kernel/own'
|
43
42
|
require 'facets/core/kernel/p'
|
43
|
+
require 'facets/core/kernel/pp_exception'
|
44
44
|
require 'facets/core/kernel/require_all'
|
45
45
|
require 'facets/core/kernel/require_esc'
|
46
46
|
require 'facets/core/kernel/require_facet'
|
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue LoadError
|
4
|
-
require 'facet/functor'
|
5
|
-
end
|
1
|
+
|
2
|
+
require 'facet/functor'
|
6
3
|
|
7
4
|
class Object
|
8
5
|
|
@@ -15,14 +12,18 @@ class Object
|
|
15
12
|
#
|
16
13
|
# c = C.new
|
17
14
|
# c.object_id #=> "OBTUSE"
|
18
|
-
# c.
|
15
|
+
# c.instance.object_id #=> 6664875832
|
19
16
|
#
|
20
|
-
|
21
|
-
|
17
|
+
#--
|
18
|
+
# Might this be better named as 'object'?
|
19
|
+
#++
|
20
|
+
|
21
|
+
def instance
|
22
|
+
@__instance__ ||= Functor.new do |meth, *args| # &blk|
|
22
23
|
Kernel.instance_method(meth).bind(self).call(*args) # ,&blk)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
alias_method :
|
27
|
+
alias_method :__instance__, :instance
|
27
28
|
|
28
29
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module Kernel
|
3
|
+
|
4
|
+
# Pretty prints an exception/error object
|
5
|
+
# usefull for helpfull debug messages
|
6
|
+
#
|
7
|
+
# Input:
|
8
|
+
# The Exception/StandardError object
|
9
|
+
#
|
10
|
+
# Output:
|
11
|
+
# the pretty printed string
|
12
|
+
|
13
|
+
def pp_exception(ex)
|
14
|
+
return %{#{ex.message}\n #{ex.backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]}}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/facets/core/module.rb
CHANGED
@@ -6,6 +6,7 @@ require 'facets/core/module/attr_setter'
|
|
6
6
|
require 'facets/core/module/attr_tester'
|
7
7
|
require 'facets/core/module/basename'
|
8
8
|
require 'facets/core/module/by_name'
|
9
|
+
require 'facets/core/module/cattr'
|
9
10
|
require 'facets/core/module/cattr_accessor'
|
10
11
|
require 'facets/core/module/cattr_reader'
|
11
12
|
require 'facets/core/module/cattr_writer'
|
@@ -24,6 +25,7 @@ require 'facets/core/module/memoize'
|
|
24
25
|
require 'facets/core/module/modspace'
|
25
26
|
require 'facets/core/module/namespace'
|
26
27
|
require 'facets/core/module/nesting'
|
28
|
+
require 'facets/core/module/on_included'
|
27
29
|
require 'facets/core/module/redef'
|
28
30
|
require 'facets/core/module/redefine_method'
|
29
31
|
require 'facets/core/module/redirect'
|
@@ -1,9 +1,12 @@
|
|
1
1
|
|
2
2
|
class Module
|
3
3
|
|
4
|
-
#
|
4
|
+
# There's a school of thought that says an attribute
|
5
5
|
# show always have a reader and a writer.
|
6
6
|
#
|
7
|
+
#--
|
8
|
+
# NOAUTO
|
9
|
+
#++
|
7
10
|
def attr(*args)
|
8
11
|
args.pop unless args.last.is_a?(Symbol) or args.last.is_a?(String)
|
9
12
|
attr_accessor *args
|
@@ -10,8 +10,19 @@ class Module
|
|
10
10
|
# Demo.name #=> Example::Demo
|
11
11
|
# Demo.basename #=> Demo
|
12
12
|
#
|
13
|
+
# For anonymous modules this will provide a basename
|
14
|
+
# based on Module#inspect.
|
15
|
+
#
|
16
|
+
# m = Module.new
|
17
|
+
# m.inspect #=> "#<Module:0xb7bb0434>"
|
18
|
+
# m.basename #=> "Module_0xb7bb0434"
|
19
|
+
#
|
13
20
|
def basename
|
14
|
-
self.name
|
21
|
+
if self.name
|
22
|
+
self.name.gsub(/^.*::/, '')
|
23
|
+
else
|
24
|
+
self.inspect.gsub('#<','').gsub('>','').sub(':', '_')
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
28
|
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#--
|
2
|
+
# Original credit goes to DHH.
|
3
|
+
#++
|
4
|
+
|
5
|
+
class Module
|
6
|
+
|
7
|
+
# Creates a class-variable attribute that can
|
8
|
+
# be accessed both on an instance and class level.
|
9
|
+
|
10
|
+
def cattr( *syms )
|
11
|
+
writer = false
|
12
|
+
syms.reject! do |s|
|
13
|
+
case s
|
14
|
+
when TrueClass
|
15
|
+
writer = true
|
16
|
+
when FalseClass, NilClass
|
17
|
+
true
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
if writer
|
23
|
+
cattr_accessor( *syms )
|
24
|
+
else
|
25
|
+
cattr_reader( *syms )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :mattr, :cattr
|
30
|
+
|
31
|
+
# Creates a class-variable attr_reader that can
|
32
|
+
# be accessed both on an instance and class level.
|
33
|
+
#
|
34
|
+
# class MyClass
|
35
|
+
# @@a = 10
|
36
|
+
# cattr_reader :a
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# MyClass.a #=> 10
|
40
|
+
# MyClass.new.a #=> 10
|
41
|
+
#
|
42
|
+
def cattr_reader( *syms )
|
43
|
+
hsyms = ( syms.last.is_a?(Hash) ? syms.pop : {} )
|
44
|
+
hsyms.update( Hash[*(syms.zip([nil]*syms.size).flatten)] )
|
45
|
+
hsyms.each_pair do |sym, val|
|
46
|
+
p sym, val
|
47
|
+
class_eval <<-EOS
|
48
|
+
if ! defined? @@#{sym}
|
49
|
+
@@#{sym} = val
|
50
|
+
end
|
51
|
+
def self.#{sym}
|
52
|
+
@@#{sym}
|
53
|
+
end
|
54
|
+
def #{sym}
|
55
|
+
self.class.#{sym}
|
56
|
+
end
|
57
|
+
EOS
|
58
|
+
end
|
59
|
+
return hsyms.keys
|
60
|
+
end
|
61
|
+
|
62
|
+
alias_method :mattr_reader, :cattr_reader
|
63
|
+
|
64
|
+
# Creates a class-variable attr_writer that can
|
65
|
+
# be accessed both on an instance and class level.
|
66
|
+
#
|
67
|
+
# class MyClass
|
68
|
+
# cattr_writer :a
|
69
|
+
# def a
|
70
|
+
# @@a
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# MyClass.a = 10
|
75
|
+
# MyClass.a #=> 10
|
76
|
+
# MyClass.new.a = 29
|
77
|
+
# MyClass.a #=> 29
|
78
|
+
#
|
79
|
+
def cattr_writer(*syms)
|
80
|
+
hsyms = ( syms.last.is_a?(Hash) ? syms.pop : {} )
|
81
|
+
hsyms.update( Hash[*(syms.zip([nil]*syms.size).flatten)] )
|
82
|
+
hsyms.each_pair do |sym, val|
|
83
|
+
class_eval <<-EOS
|
84
|
+
if ! defined? @@#{sym}
|
85
|
+
@@#{sym} = val
|
86
|
+
end
|
87
|
+
def self.#{sym}=(obj)
|
88
|
+
@@#{sym} = obj
|
89
|
+
end
|
90
|
+
def #{sym}=(obj)
|
91
|
+
self.class.#{sym}=(obj)
|
92
|
+
end
|
93
|
+
EOS
|
94
|
+
end
|
95
|
+
return hsyms.keys
|
96
|
+
end
|
97
|
+
|
98
|
+
alias_method :mattr_writer, :cattr_writer
|
99
|
+
|
100
|
+
# Creates a class-variable attr_accessor that can
|
101
|
+
# be accessed both on an instance and class level.
|
102
|
+
#
|
103
|
+
# class MyClass
|
104
|
+
# cattr_accessor :a
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# MyClass.a = 10
|
108
|
+
# MyClass.a #=> 10
|
109
|
+
# mc = MyClass.new
|
110
|
+
# mc.a #=> 10
|
111
|
+
#
|
112
|
+
def cattr_accessor(*syms)
|
113
|
+
m = []
|
114
|
+
m.concat( cattr_reader(*syms) )
|
115
|
+
m.concat( cattr_writer(*syms) )
|
116
|
+
m
|
117
|
+
end
|
118
|
+
|
119
|
+
alias_method :mattr_accessor, :cattr_accessor
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# _____ _
|
126
|
+
# |_ _|__ ___| |_
|
127
|
+
# | |/ _ \/ __| __|
|
128
|
+
# | | __/\__ \ |_
|
129
|
+
# |_|\___||___/\__|
|
130
|
+
#
|
131
|
+
=begin test
|
132
|
+
|
133
|
+
require 'test/unit'
|
134
|
+
|
135
|
+
class TCModule < Test::Unit::TestCase
|
136
|
+
|
137
|
+
class MockObject
|
138
|
+
def initialize
|
139
|
+
@@a = 10
|
140
|
+
end
|
141
|
+
def b ; @@b ; end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_cattr
|
145
|
+
assert_nothing_raised {
|
146
|
+
MockObject.class_eval { cattr :a }
|
147
|
+
}
|
148
|
+
t = MockObject.new
|
149
|
+
assert_equal( 10, t.a )
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_cattr_reader
|
153
|
+
assert_nothing_raised {
|
154
|
+
MockObject.class_eval { cattr_reader :a }
|
155
|
+
}
|
156
|
+
t = MockObject.new
|
157
|
+
assert_equal( 10, t.a )
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_cattr_writer
|
161
|
+
assert_nothing_raised {
|
162
|
+
MockObject.class_eval { cattr_writer :b }
|
163
|
+
}
|
164
|
+
t = MockObject.new
|
165
|
+
t.b = 5
|
166
|
+
assert_equal( 5, t.b )
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_cattr_accessor
|
170
|
+
assert_nothing_raised {
|
171
|
+
MockObject.class_eval { cattr_accessor :c }
|
172
|
+
}
|
173
|
+
t = MockObject.new
|
174
|
+
t.c = 50
|
175
|
+
assert_equal( 50, t.c )
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
=end
|