├── demo ├── applique │ └── assertion_framework.rb └── core │ ├── binding │ ├── self.md │ ├── defined.md │ └── opvars.md │ ├── dir │ ├── parent.md │ ├── descend.md │ └── ascend.md │ ├── string │ ├── unquote.md │ ├── op_sub.md │ ├── variablize.md │ ├── titlecase.md │ ├── interpolate.md │ ├── store.md │ ├── xor.md │ ├── line_wrap.md │ ├── rewrite.md │ ├── subtract.md │ ├── each_word.md │ ├── divide.md │ ├── lowercase.md │ ├── unfold.md │ ├── acronym.md │ ├── shatter.md │ ├── lchomp.md │ ├── mscan.md │ ├── newlines.md │ ├── nchar.md │ ├── op_div.md │ ├── uppercase.md │ ├── words.md │ ├── cleanlines.md │ ├── exclude.md │ ├── pathize.md │ ├── natcmp.md │ ├── modulize.md │ ├── methodize.md │ └── snakecase.md │ ├── facets.md │ ├── integer │ ├── length.md │ ├── times_collect.md │ ├── of.md │ ├── factorial.md │ ├── ordinal.md │ └── multiple.md │ ├── matchdata │ ├── match.md │ ├── matchset.md │ └── matchtree.md │ ├── array │ ├── not_empty.md │ ├── zip.md │ ├── contains.md │ ├── store.md │ ├── only.md │ ├── last.md │ ├── delete_values.md │ ├── peek.md │ ├── first.md │ ├── from.md │ ├── pull.md │ ├── merge.md │ ├── duplicates.md │ ├── probability │ ├── recurse.md │ ├── op_pow.md │ ├── mode.md │ ├── reject_values.md │ ├── thru.md │ ├── squeeze.md │ ├── to_h.md │ ├── each_value.md │ ├── poke.md │ ├── entropy.md │ ├── missing.md │ ├── split.md │ ├── delete_unless.md │ ├── nonuniq.md │ ├── occurrence.md │ ├── split_at.md │ ├── ideal_entropy.md │ ├── splice.md │ └── collapse.md │ ├── comparable │ ├── cap.md │ ├── at_most.md │ ├── at_least.md │ └── bound.md │ ├── class │ ├── descendants.md │ └── to_proc.md │ └── filetest │ └── root.md ├── lib ├── core │ └── facets │ │ ├── cattr.rb │ │ ├── string │ │ ├── roman.rb │ │ ├── op_sub.rb │ │ ├── to_rx.rb │ │ ├── cmp.rb │ │ ├── outdent.rb │ │ ├── unquote.rb │ │ ├── briefcase.rb │ │ ├── each_match.rb │ │ ├── lowercase.rb │ │ ├── range_all.rb │ │ ├── range_of_line.rb │ │ ├── unbracket.rb │ │ ├── unindent.rb │ │ ├── ends_with.rb │ │ ├── underscore.rb │ │ ├── store.rb │ │ ├── subtract.rb │ │ ├── starts_with.rb │ │ ├── indexable.rb │ │ ├── exclude.rb │ │ ├── acronym.rb │ │ ├── variablize.rb │ │ ├── op_div.rb │ │ ├── each_word.rb │ │ └── number.rb │ │ ├── time │ │ ├── hence.rb │ │ ├── in.rb │ │ ├── ago.rb │ │ ├── less.rb │ │ ├── past.rb │ │ ├── future.rb │ │ ├── trunc.rb │ │ └── elapse.rb │ │ ├── array │ │ ├── peek.rb │ │ ├── poke.rb │ │ ├── thru.rb │ │ ├── after.rb │ │ ├── first.rb │ │ ├── last.rb │ │ ├── collisions.rb │ │ ├── delete_values_at.rb │ │ ├── contains.rb │ │ ├── delete.rb │ │ ├── each_value.rb │ │ ├── not_empty.rb │ │ ├── each_pair.rb │ │ ├── store.rb │ │ ├── delete_unless.rb │ │ ├── collapse.rb │ │ ├── op_pow.rb │ │ ├── to_h.rb │ │ ├── average.rb │ │ └── merge.rb │ │ ├── dir │ │ ├── descend.rb │ │ └── parent.rb │ │ ├── hash │ │ ├── mash.rb │ │ ├── only_keys.rb │ │ ├── to_options.rb │ │ ├── stringify_keys.rb │ │ ├── delete_at.rb │ │ ├── at.rb │ │ ├── delete.rb │ │ ├── op_add.rb │ │ ├── op_or.rb │ │ ├── op.rb │ │ ├── update.rb │ │ ├── each_with_key.rb │ │ ├── count.rb │ │ ├── new_with.rb │ │ ├── replace_each.rb │ │ ├── swap.rb │ │ ├── op_mul.rb │ │ ├── insert.rb │ │ ├── delete_unless.rb │ │ └── diff.rb │ │ ├── integer │ │ ├── roman.rb │ │ ├── bit.rb │ │ ├── multiple.rb │ │ └── of.rb │ │ ├── kernel │ │ ├── no.rb │ │ ├── presence.rb │ │ ├── present.rb │ │ ├── __set__.rb │ │ ├── assign_from.rb │ │ ├── false.rb │ │ ├── call_stack.rb │ │ ├── load_all.rb │ │ ├── eigen.rb │ │ ├── enable_warnings.rb │ │ ├── silence_warnings.rb │ │ ├── identical.rb │ │ ├── instance_send.rb │ │ ├── case.rb │ │ ├── here.rb │ │ ├── extension.rb │ │ ├── object_class.rb │ │ ├── in.rb │ │ ├── __class__.rb │ │ ├── singleton_class.rb │ │ ├── super_method.rb │ │ ├── not_nil.rb │ │ ├── deep_copy.rb │ │ └── with.rb │ │ ├── module │ │ ├── op_add.rb │ │ ├── op_mul.rb │ │ ├── op_sub.rb │ │ ├── cattr.rb │ │ ├── extend.rb │ │ ├── homename.rb │ │ ├── housing.rb │ │ ├── remove.rb │ │ ├── basename.rb │ │ ├── modname.rb │ │ ├── enclosures.rb │ │ ├── include_as.rb │ │ ├── class_def.rb │ │ ├── class_method_defined.rb │ │ ├── singleton_method_defined.rb │ │ ├── alias_class_method.rb │ │ ├── class.rb │ │ ├── ancestor.rb │ │ ├── to_obj.rb │ │ ├── can.rb │ │ └── memoize.rb │ │ ├── object │ │ ├── clone.rb │ │ ├── try_dup.rb │ │ └── itself.rb │ │ ├── class │ │ ├── cattr.rb │ │ ├── singleton.rb │ │ ├── hierarchically.rb │ │ ├── singleton_class.rb │ │ ├── pathize.rb │ │ └── methodize.rb │ │ ├── load_path.rb │ │ ├── nilclass │ │ └── ergo.rb │ │ ├── numeric │ │ ├── close.rb │ │ ├── negative.rb │ │ ├── length.rb │ │ ├── positive.rb │ │ ├── range.rb │ │ └── distance.rb │ │ ├── range │ │ ├── umbrella.rb │ │ ├── overlap.rb │ │ └── op_add.rb │ │ ├── symbol │ │ ├── bang.rb │ │ ├── query.rb │ │ ├── reader.rb │ │ ├── setter.rb │ │ ├── writer.rb │ │ └── variablize.rb │ │ ├── binding │ │ ├── __callee__.rb │ │ ├── __method__.rb │ │ ├── op_set.rb │ │ ├── call_stack.rb │ │ ├── callstack.rb │ │ ├── op.rb │ │ ├── defined.rb │ │ ├── with.rb │ │ └── self.rb │ │ ├── comparable │ │ ├── at_most.rb │ │ ├── bound.rb │ │ └── at_least.rb │ │ ├── float.rb │ │ ├── float │ │ └── round_to.rb │ │ ├── method │ │ ├── op_mul.rb │ │ ├── op_pow.rb │ │ ├── partial.rb │ │ └── curry.rb │ │ ├── nilclass.rb │ │ ├── process.rb │ │ ├── enumerable │ │ ├── zip_map.rb │ │ ├── map_detect.rb │ │ ├── collect_with_index.rb │ │ ├── associate.rb │ │ ├── expand.rb │ │ ├── map_to.rb │ │ ├── uniq_by.rb │ │ └── exclude.rb │ │ ├── filetest │ │ ├── absolute.rb │ │ ├── contains.rb │ │ └── root.rb │ │ ├── unboundmethod.rb │ │ ├── objectspace │ │ ├── op_fetch.rb │ │ └── classes.rb │ │ ├── matchdata │ │ ├── matchtree.rb │ │ └── match.rb │ │ ├── struct.rb │ │ ├── matchdata.rb │ │ ├── objectspace.rb │ │ ├── exception.rb │ │ ├── file │ │ ├── atomic_id.rb │ │ ├── append.rb │ │ ├── split_root.rb │ │ ├── null.rb │ │ └── read_binary.rb │ │ ├── proc │ │ └── update.rb │ │ ├── exception │ │ ├── set_message.rb │ │ └── raised.rb │ │ ├── method.rb │ │ ├── regexp.rb │ │ ├── struct │ │ ├── replace.rb │ │ └── attributes.rb │ │ ├── metaid.rb │ │ ├── dir.rb │ │ ├── proc.rb │ │ ├── regexp │ │ ├── multiline.rb │ │ ├── to_proc.rb │ │ ├── op_add.rb │ │ └── op_or.rb │ │ ├── filetest.rb │ │ ├── object.rb │ │ ├── numeric.rb │ │ ├── integer.rb │ │ ├── comparable.rb │ │ ├── load_path │ │ └── search.rb │ │ ├── range.rb │ │ ├── version.rb │ │ └── class.rb └── standard │ └── facets │ ├── math │ ├── cosec.rb │ ├── max.rb │ ├── pstd.rb │ ├── acosec.rb │ ├── cosech.rb │ ├── stderr.rb │ ├── pvariance.rb │ ├── ec.rb │ ├── tau.rb │ ├── sqr.rb │ ├── abs.rb │ ├── exp2.rb │ ├── sec.rb │ ├── exp10.rb │ ├── asec.rb │ ├── cot.rb │ ├── root.rb │ ├── sech.rb │ ├── acot.rb │ ├── ceil.rb │ ├── coth.rb │ ├── floor.rb │ ├── sinc.rb │ ├── round.rb │ ├── asech.rb │ ├── acoth.rb │ ├── acsch.rb │ ├── tgamma.rb │ ├── csc.rb │ ├── pow.rb │ ├── acsc.rb │ ├── delta.rb │ ├── csch.rb │ ├── log2.rb │ ├── cdf.rb │ ├── mean.rb │ ├── approx_equal.rb │ ├── summed_sqdevs.rb │ ├── beta.rb │ ├── linsolve.rb │ ├── sum.rb │ ├── lcm.rb │ └── atkinson_index.rb │ ├── find.rb │ ├── uri │ ├── cgi_parse.rb │ └── cgi_unescape.rb │ ├── fileutils │ ├── head.rb │ └── tail.rb │ ├── ostruct │ ├── op_store.rb │ ├── to_h.rb │ └── each.rb │ ├── digest.rb │ ├── cgi.rb │ ├── pathname │ ├── exists.rb │ ├── rootname.rb │ ├── split_root.rb │ ├── empty.rb │ ├── to_str.rb │ ├── root.rb │ ├── work.rb │ ├── op_fetch.rb │ ├── uptodate.rb │ ├── home.rb │ ├── chdir.rb │ ├── safe.rb │ ├── op_div.rb │ ├── outofdate.rb │ ├── null.rb │ └── readline.rb │ ├── yaml.rb │ ├── yaml │ └── read.rb │ └── cgi │ └── esc.rb ├── work ├── trash │ ├── site-jekyll │ │ ├── .till │ │ ├── .htaccess │ │ ├── .rsync-filter │ │ ├── _config.yml │ │ └── assets │ │ │ └── scripts │ │ │ └── hover.js │ └── site │ │ ├── .htaccess │ │ ├── .rsync-filter │ │ └── js │ │ └── hover.js ├── bench │ └── general │ │ ├── comment_loading │ │ └── comments_none.rb │ │ └── bench_methods.rb ├── OLD_COMPARE │ └── facets │ │ └── string │ │ ├── tab.rb │ │ ├── plural.rb │ │ ├── tabto.rb │ │ ├── to_rx.rb │ │ ├── uppercase.rb │ │ ├── align_left.rb │ │ ├── align_right.rb │ │ ├── ends_with.rb │ │ ├── at.rb │ │ ├── shell_escape.rb │ │ ├── ordinal.rb │ │ └── pull.rb ├── site │ └── posts │ │ └── tomslib.rb ├── consider │ ├── standard │ │ └── math │ │ │ ├── algebra.rb │ │ │ └── finance.rb │ └── core │ │ ├── object │ │ └── class_def.rb │ │ ├── module │ │ ├── instance_class_method.rb │ │ ├── aliased_methods.rb │ │ ├── subfield_accessors.rb │ │ └── bool_accessor.rb │ │ └── enumerator.rb ├── reference │ └── tmatrix.rb ├── rejected │ ├── hash │ │ └── op_div.rb │ ├── test_continuation.rb │ └── module │ │ └── module_method.rb └── sandbox │ └── safe-study │ ├── safe_study.rb │ └── safe_extension.rb ├── test ├── standard │ ├── test_math.rb │ ├── math │ │ ├── test_factorial.rb │ │ ├── test_percentile.rb │ │ ├── test_abs.rb │ │ ├── test_lcm.rb │ │ ├── test_cot.rb │ │ ├── test_coth.rb │ │ ├── test_median.rb │ │ ├── test_exp2.rb │ │ ├── test_exp10.rb │ │ └── test_sinc.rb │ └── pathname │ │ └── test_chdir.rb └── core │ ├── kernel │ ├── test_ask.rb │ ├── test_d.rb │ ├── test_maybe.rb │ ├── test_require_all.rb │ ├── test_here.rb │ ├── test_in.rb │ ├── test_class.rb │ ├── test_meta_def.rb │ ├── test_deep_copy.rb │ ├── test_instance_class.rb │ ├── test_singleton_class.rb │ ├── test_callstack.rb │ ├── test_with.rb │ ├── test_extension.rb │ ├── test_complete.rb │ ├── test_meta_alias.rb │ ├── test_returning.rb │ ├── test_meta_eval.rb │ ├── test_instance_assign.rb │ ├── test_not_nil.rb │ └── test_object_class.rb │ ├── file │ ├── test_null.rb │ ├── test_rootname.rb │ ├── test_split_all.rb │ ├── test_create.rb │ ├── test_read_list.rb │ └── test_write.rb │ ├── filetest │ └── test_root.rb │ ├── string │ ├── test_unquote.rb │ ├── test_cleanlines.rb │ ├── test_op_sub.rb │ ├── test_variablize.rb │ ├── test_store.rb │ ├── test_file.rb │ ├── test_op_div.rb │ ├── test_titlecase.rb │ ├── test_interpolate.rb │ ├── test_margin.rb │ ├── test_acronym.rb │ ├── test_line_wrap.rb │ ├── test_xor.rb │ ├── test_lowercase.rb │ ├── test_rewrite.rb │ ├── test_each_word.rb │ ├── test_subtract.rb │ ├── test_divide.rb │ ├── test_unfold.rb │ ├── test_newlines.rb │ ├── test_shatter.rb │ ├── test_crypt.rb │ ├── test_mscan.rb │ ├── test_nchar.rb │ ├── test_edit_distance.rb │ ├── test_cmp.rb │ ├── test_uppercase.rb │ └── test_lchomp.rb │ ├── dir │ ├── test_parent.rb │ └── test_each_child.rb │ ├── module │ ├── test_modname.rb │ ├── test_basename.rb │ ├── test_ancestor.rb │ ├── test_spacename.rb │ ├── test_anonymous.rb │ ├── test_can.rb │ ├── test_to_obj.rb │ ├── test_remove.rb │ ├── test_nodef.rb │ ├── test_instance_method.rb │ └── test_pathize.rb │ ├── array │ ├── test_zip.rb │ ├── test_op_pow.rb │ ├── test_pull.rb │ ├── test_to_h.rb │ ├── test_contains.rb │ ├── test_not_empty.rb │ ├── test_last.rb │ ├── test_first.rb │ ├── test_mode.rb │ ├── test_each_value.rb │ ├── test_only.rb │ ├── test_each_pair.rb │ ├── test_missing.rb │ ├── test_reject_values.rb │ ├── test_probability.rb │ ├── test_poke.rb │ ├── test_splice.rb │ ├── test_store.rb │ ├── test_delete_unless.rb │ ├── test_split.rb │ └── test_entropy.rb │ ├── symbol │ ├── test_as_s.rb │ ├── test_variablize.rb │ ├── test_bang.rb │ ├── test_succ.rb │ ├── test_op_div.rb │ ├── test_setter.rb │ ├── test_not.rb │ ├── test_plain.rb │ ├── test_query.rb │ └── test_chomp.rb │ ├── regexp │ ├── test_op_add.rb │ ├── test_op_or.rb │ ├── test_multiline.rb │ └── test_to_re.rb │ ├── time │ ├── test_to_time.rb │ ├── test_elapse.rb │ └── test_change.rb │ ├── binding │ ├── test_self.rb │ ├── test_defined.rb │ └── test_op.rb │ ├── proc │ ├── test_update.rb │ └── test_bind_to.rb │ ├── hash │ ├── test_swap.rb │ ├── test_at.rb │ ├── test_zip.rb │ ├── test_op_mul.rb │ ├── test_op_or.rb │ ├── test_diff.rb │ ├── test_new_with.rb │ ├── test_update_values.rb │ ├── test_each_with_key.rb │ ├── test_op_add.rb │ ├── test_delete_at.rb │ ├── test_update_each.rb │ ├── test_replace_each.rb │ ├── test_inverse.rb │ ├── test_delete_unless.rb │ ├── test_insert.rb │ ├── test_to_proc.rb │ └── test_weave.rb │ ├── matchdata │ └── test_match.rb │ ├── enumerable │ ├── test_expand.rb │ ├── test_visit.rb │ ├── test_exclude.rb │ ├── test_modulate.rb │ ├── test_frequency.rb │ ├── test_per.rb │ └── test_mash.rb │ ├── enumerator │ └── test_fx.rb │ ├── range │ ├── test_overlap.rb │ └── test_to_rng.rb │ ├── exception │ ├── test_raised.rb │ ├── test_detail.rb │ └── test_suppress.rb │ ├── numeric │ ├── test_length.rb │ └── test_distance.rb │ ├── comparable │ └── test_cmp.rb │ ├── class │ ├── test_to_proc.rb │ ├── test_descendents.rb │ └── test_subclasses.rb │ ├── integer │ └── test_multiple.rb │ └── struct │ └── test_replace.rb ├── .yardopts └── .gitignore /demo/applique/assertion_framework.rb: -------------------------------------------------------------------------------- 1 | require 'ae' 2 | -------------------------------------------------------------------------------- /lib/core/facets/cattr.rb: -------------------------------------------------------------------------------- 1 | require 'facets/class/cattr' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/roman.rb: -------------------------------------------------------------------------------- 1 | require 'facets/roman' 2 | -------------------------------------------------------------------------------- /lib/core/facets/time/hence.rb: -------------------------------------------------------------------------------- 1 | require 'facets/time/in' 2 | -------------------------------------------------------------------------------- /lib/core/facets/time/in.rb: -------------------------------------------------------------------------------- 1 | require 'facets/time/shift' 2 | -------------------------------------------------------------------------------- /work/trash/site-jekyll/.till: -------------------------------------------------------------------------------- 1 | sh "jekyll . ../../doc/" 2 | -------------------------------------------------------------------------------- /work/trash/site/.htaccess: -------------------------------------------------------------------------------- 1 | DirectoryIndex index.xml 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/peek.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/pull' 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/poke.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/pull' 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/thru.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/from' 2 | -------------------------------------------------------------------------------- /lib/core/facets/dir/descend.rb: -------------------------------------------------------------------------------- 1 | require 'facets/dir/ascend' 2 | -------------------------------------------------------------------------------- /lib/core/facets/hash/mash.rb: -------------------------------------------------------------------------------- 1 | require 'facets/hash/graph' 2 | -------------------------------------------------------------------------------- /lib/core/facets/integer/roman.rb: -------------------------------------------------------------------------------- 1 | require 'facets/roman' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/no.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/yes' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/op_add.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/op' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/op_mul.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/op' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/op_sub.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/op' 2 | -------------------------------------------------------------------------------- /lib/core/facets/object/clone.rb: -------------------------------------------------------------------------------- 1 | require 'facets/object/dup' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/op_sub.rb: -------------------------------------------------------------------------------- 1 | require_relative 'remove' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/to_rx.rb: -------------------------------------------------------------------------------- 1 | require_relative 'to_re' 2 | -------------------------------------------------------------------------------- /lib/core/facets/time/ago.rb: -------------------------------------------------------------------------------- 1 | require 'facets/time/shift' 2 | -------------------------------------------------------------------------------- /lib/core/facets/time/less.rb: -------------------------------------------------------------------------------- 1 | require 'facets/time/shift' 2 | -------------------------------------------------------------------------------- /lib/core/facets/time/past.rb: -------------------------------------------------------------------------------- 1 | require 'facets/time/future' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/math/cosec.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/csc' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/math/max.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/min' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/math/pstd.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/std' 2 | -------------------------------------------------------------------------------- /work/bench/general/comment_loading/comments_none.rb: -------------------------------------------------------------------------------- 1 | a = 1 2 | -------------------------------------------------------------------------------- /work/trash/site-jekyll/.htaccess: -------------------------------------------------------------------------------- 1 | DirectoryIndex index.html 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/after.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/before' 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/first.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/indexable' 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/last.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/indexable' 2 | -------------------------------------------------------------------------------- /lib/core/facets/class/cattr.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/cattr' 2 | -------------------------------------------------------------------------------- /lib/core/facets/hash/only_keys.rb: -------------------------------------------------------------------------------- 1 | require 'facets/hash/keys' 2 | -------------------------------------------------------------------------------- /lib/core/facets/integer/bit.rb: -------------------------------------------------------------------------------- 1 | require 'facets/integer/bitmask' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/presence.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/blank' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/present.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/blank' 2 | -------------------------------------------------------------------------------- /lib/core/facets/load_path.rb: -------------------------------------------------------------------------------- 1 | require_relative 'load_path/search' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/cattr.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/mattr' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/extend.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/extend' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/homename.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/home' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/housing.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/home' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/remove.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/nodef' 2 | -------------------------------------------------------------------------------- /lib/core/facets/nilclass/ergo.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/ergo' 2 | -------------------------------------------------------------------------------- /lib/core/facets/numeric/close.rb: -------------------------------------------------------------------------------- 1 | require 'facets/numeric/approx' 2 | -------------------------------------------------------------------------------- /lib/core/facets/object/try_dup.rb: -------------------------------------------------------------------------------- 1 | require 'facets/object/dup' 2 | -------------------------------------------------------------------------------- /lib/core/facets/range/umbrella.rb: -------------------------------------------------------------------------------- 1 | require 'facets/range/within' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/cmp.rb: -------------------------------------------------------------------------------- 1 | require 'facets/comparable/cmp' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/outdent.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/indent' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/unquote.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/quote' 2 | -------------------------------------------------------------------------------- /lib/core/facets/symbol/bang.rb: -------------------------------------------------------------------------------- 1 | require 'facets/symbol/plain' 2 | -------------------------------------------------------------------------------- /lib/core/facets/symbol/query.rb: -------------------------------------------------------------------------------- 1 | require 'facets/symbol/plain' 2 | -------------------------------------------------------------------------------- /lib/core/facets/symbol/reader.rb: -------------------------------------------------------------------------------- 1 | require 'facets/symbol/plain' 2 | -------------------------------------------------------------------------------- /lib/core/facets/symbol/setter.rb: -------------------------------------------------------------------------------- 1 | require 'facets/symbol/plain' 2 | -------------------------------------------------------------------------------- /lib/core/facets/symbol/writer.rb: -------------------------------------------------------------------------------- 1 | require 'facets/symbol/plain' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/find.rb: -------------------------------------------------------------------------------- 1 | require 'facets/find/select' 2 | 3 | -------------------------------------------------------------------------------- /lib/standard/facets/math/acosec.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/acsc' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/math/cosech.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/csch' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/math/stderr.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/std' 2 | -------------------------------------------------------------------------------- /lib/core/facets/binding/__callee__.rb: -------------------------------------------------------------------------------- 1 | require 'facets/binding/caller' 2 | -------------------------------------------------------------------------------- /lib/core/facets/binding/__method__.rb: -------------------------------------------------------------------------------- 1 | require 'facets/binding/caller' 2 | -------------------------------------------------------------------------------- /lib/core/facets/binding/op_set.rb: -------------------------------------------------------------------------------- 1 | require 'facets/binding/op_get' 2 | -------------------------------------------------------------------------------- /lib/core/facets/comparable/at_most.rb: -------------------------------------------------------------------------------- 1 | require 'facets/comparable/cap' 2 | -------------------------------------------------------------------------------- /lib/core/facets/comparable/bound.rb: -------------------------------------------------------------------------------- 1 | require 'facets/comparable/clip' 2 | -------------------------------------------------------------------------------- /lib/core/facets/float.rb: -------------------------------------------------------------------------------- 1 | require_relative 'float/round_to.rb' 2 | 3 | -------------------------------------------------------------------------------- /lib/core/facets/float/round_to.rb: -------------------------------------------------------------------------------- 1 | require 'facets/numeric/round_to' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/__set__.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/__get__' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/assign_from.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/assign' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/false.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/true' 2 | 3 | -------------------------------------------------------------------------------- /lib/core/facets/method/op_mul.rb: -------------------------------------------------------------------------------- 1 | require 'facets/method/composition' 2 | -------------------------------------------------------------------------------- /lib/core/facets/method/op_pow.rb: -------------------------------------------------------------------------------- 1 | require 'facets/method/composition' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/basename.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/lastname' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/modname.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/homename' 2 | -------------------------------------------------------------------------------- /lib/core/facets/nilclass.rb: -------------------------------------------------------------------------------- 1 | require_relative 'nilclass/ergo.rb' 2 | 3 | -------------------------------------------------------------------------------- /lib/core/facets/numeric/negative.rb: -------------------------------------------------------------------------------- 1 | require 'facets/numeric/positive' 2 | -------------------------------------------------------------------------------- /lib/core/facets/process.rb: -------------------------------------------------------------------------------- 1 | require_relative 'process/daemon.rb' 2 | 3 | -------------------------------------------------------------------------------- /lib/core/facets/string/briefcase.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/titlecase' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/each_match.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/mscan' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/lowercase.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/uppercase' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/range_all.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/range' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/range_of_line.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/range' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/unbracket.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/bracket' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/unindent.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/indent' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/math/pvariance.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/variance' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/uri/cgi_parse.rb: -------------------------------------------------------------------------------- 1 | require 'facets/uri/cgi_escape' 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/collisions.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/commonality' 2 | -------------------------------------------------------------------------------- /lib/core/facets/binding/call_stack.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/callstack' 2 | -------------------------------------------------------------------------------- /lib/core/facets/binding/callstack.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/callstack' 2 | -------------------------------------------------------------------------------- /lib/core/facets/class/singleton.rb: -------------------------------------------------------------------------------- 1 | require 'facets/class/singleton_class' 2 | -------------------------------------------------------------------------------- /lib/core/facets/comparable/at_least.rb: -------------------------------------------------------------------------------- 1 | require 'facets/comparable/cap' 2 | -------------------------------------------------------------------------------- /lib/core/facets/enumerable/zip_map.rb: -------------------------------------------------------------------------------- 1 | require 'facets/enumerable/map_with' 2 | -------------------------------------------------------------------------------- /lib/core/facets/filetest/absolute.rb: -------------------------------------------------------------------------------- 1 | require 'facets/filetest/relative' 2 | -------------------------------------------------------------------------------- /lib/core/facets/hash/to_options.rb: -------------------------------------------------------------------------------- 1 | require 'facets/hash/symbolize_keys' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/call_stack.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/callstack' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/load_all.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/require_all' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/enclosures.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/enclosure' 2 | -------------------------------------------------------------------------------- /lib/core/facets/module/include_as.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/method_space' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/ends_with.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/starts_with' 2 | -------------------------------------------------------------------------------- /lib/core/facets/string/underscore.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/snakecase' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/fileutils/head.rb: -------------------------------------------------------------------------------- 1 | require 'facets/fileutils/slice' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/fileutils/tail.rb: -------------------------------------------------------------------------------- 1 | require 'facets/fileutils/slice' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/ostruct/op_store.rb: -------------------------------------------------------------------------------- 1 | require 'facets/ostruct/op_fetch' 2 | -------------------------------------------------------------------------------- /lib/standard/facets/uri/cgi_unescape.rb: -------------------------------------------------------------------------------- 1 | require 'facets/uri/cgi_escape' 2 | -------------------------------------------------------------------------------- /lib/core/facets/array/delete_values_at.rb: -------------------------------------------------------------------------------- 1 | require 'facets/array/delete_values' 2 | -------------------------------------------------------------------------------- /lib/core/facets/enumerable/map_detect.rb: -------------------------------------------------------------------------------- 1 | require 'facets/enumerable/find_yield' 2 | -------------------------------------------------------------------------------- /lib/core/facets/hash/stringify_keys.rb: -------------------------------------------------------------------------------- 1 | require 'facets/hash/symbolize_keys' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/eigen.rb: -------------------------------------------------------------------------------- 1 | # Deprecated! 2 | require 'facets/kernel/meta' 3 | -------------------------------------------------------------------------------- /lib/core/facets/module/class_def.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/module_def' 2 | 3 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/tab.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/indent' 3 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/enable_warnings.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/disable_warnings' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/silence_warnings.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/disable_warnings' 2 | -------------------------------------------------------------------------------- /lib/core/facets/unboundmethod.rb: -------------------------------------------------------------------------------- 1 | require_relative 'unboundmethod/arguments.rb' 2 | 3 | -------------------------------------------------------------------------------- /test/standard/test_math.rb: -------------------------------------------------------------------------------- 1 | # test the math require 2 | require 'facets/math' 3 | 4 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/plural.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/singular' 3 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/tabto.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/indent' 3 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/to_rx.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/to_re' 3 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/uppercase.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/upcase' 3 | -------------------------------------------------------------------------------- /lib/core/facets/module/class_method_defined.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/instance_method_defined' 2 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/align_left.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/align_center' 3 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/align_right.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/align_center' 3 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/ends_with.rb: -------------------------------------------------------------------------------- 1 | # stub 2 | require 'facets/string/starts_with' 3 | -------------------------------------------------------------------------------- /lib/core/facets/enumerable/collect_with_index.rb: -------------------------------------------------------------------------------- 1 | require 'facets/enumerable/map_with_index' 2 | 3 | -------------------------------------------------------------------------------- /lib/core/facets/module/singleton_method_defined.rb: -------------------------------------------------------------------------------- 1 | require 'facets/module/instance_method_defined' 2 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/identical.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | alias_method :identical?, :equal? 3 | end 4 | 5 | -------------------------------------------------------------------------------- /lib/core/facets/objectspace/op_fetch.rb: -------------------------------------------------------------------------------- 1 | class << ObjectSpace 2 | alias_method :[], :_id2ref 3 | end 4 | -------------------------------------------------------------------------------- /work/site/posts/tomslib.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/facets/main/work/site/posts/tomslib.rb -------------------------------------------------------------------------------- /lib/standard/facets/digest.rb: -------------------------------------------------------------------------------- 1 | require 'facets/digest/base64digest' 2 | require 'facets/digest/salted_digest' 3 | -------------------------------------------------------------------------------- /lib/core/facets/matchdata/matchtree.rb: -------------------------------------------------------------------------------- 1 | # Matchdata#matchtree is defined in 2 | require 'facets/matchdata/matchset' 3 | -------------------------------------------------------------------------------- /lib/core/facets/struct.rb: -------------------------------------------------------------------------------- 1 | require_relative 'struct/attributes.rb' 2 | require_relative 'struct/replace.rb' 3 | 4 | -------------------------------------------------------------------------------- /lib/core/facets/matchdata.rb: -------------------------------------------------------------------------------- 1 | require_relative 'matchdata/match.rb' 2 | require_relative 'matchdata/matchset.rb' 3 | 4 | -------------------------------------------------------------------------------- /lib/standard/facets/math/ec.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | # Euler's constant. 3 | EC = 0.577_215_664_901_532_861 4 | end 5 | 6 | -------------------------------------------------------------------------------- /lib/standard/facets/math/tau.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | # See http://tauday.com/tau-manifesto 3 | TAU = 2 * PI 4 | end 5 | 6 | -------------------------------------------------------------------------------- /demo/core/binding/self.md: -------------------------------------------------------------------------------- 1 | ## Binding#self 2 | 3 | require 'facets/binding/self' 4 | 5 | binding.self == self 6 | 7 | -------------------------------------------------------------------------------- /lib/core/facets/objectspace.rb: -------------------------------------------------------------------------------- 1 | require_relative 'objectspace/classes.rb' 2 | require_relative 'objectspace/op_fetch.rb' 3 | 4 | -------------------------------------------------------------------------------- /lib/core/facets/string/store.rb: -------------------------------------------------------------------------------- 1 | class String 2 | 3 | # Alias for []=. 4 | alias_method :store, :[]= 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /lib/core/facets/string/subtract.rb: -------------------------------------------------------------------------------- 1 | # TODO: Deprecate string/subtract file. 2 | # 3 | require 'facets/string/op_sub' 4 | 5 | -------------------------------------------------------------------------------- /work/consider/standard/math/algebra.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/facets/main/work/consider/standard/math/algebra.rb -------------------------------------------------------------------------------- /lib/standard/facets/cgi.rb: -------------------------------------------------------------------------------- 1 | require 'cgi' 2 | 3 | require 'facets/cgi/marshal' 4 | require 'facets/cgi/escape_html' 5 | 6 | 7 | -------------------------------------------------------------------------------- /work/trash/site-jekyll/.rsync-filter: -------------------------------------------------------------------------------- 1 | - .svn 2 | P usage 3 | P statcvs 4 | P statsvn 5 | P robot.txt 6 | P robots.txt 7 | P wiki 8 | -------------------------------------------------------------------------------- /lib/standard/facets/math/sqr.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Square of number. 4 | def self.sqr(x) 5 | x * x 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /demo/core/dir/parent.md: -------------------------------------------------------------------------------- 1 | ## Dir#parent 2 | 3 | require 'facets/dir/parent' 4 | 5 | Dir.assert.parent?("a/b/c", "a/b/c/d") 6 | 7 | -------------------------------------------------------------------------------- /lib/core/facets/array/contains.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | 3 | # Alias for #include?. 4 | alias_method :contains?, :include? 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /lib/core/facets/string/starts_with.rb: -------------------------------------------------------------------------------- 1 | class String 2 | alias starts_with? start_with? 3 | alias ends_with? end_with? 4 | end 5 | 6 | -------------------------------------------------------------------------------- /lib/standard/facets/math/abs.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Absolute value of +x+. 4 | def self.abs(x) 5 | x.abs 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/exp2.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # 2 to the power +x+ 4 | def self.exp2(x) 5 | 2.0 ** x 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/sec.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Secans of +x+. 4 | def self.sec(x) 5 | 1.0 / cos(x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /demo/core/string/unquote.md: -------------------------------------------------------------------------------- 1 | ## String#unquote 2 | 3 | require 'facets/string/unquote' 4 | 5 | "'this'".unquote.assert == "this" 6 | 7 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/instance_send.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | # Private send. 4 | alias_method :instance_send, :__send__ 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /lib/standard/facets/math/exp10.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # 10 to the power +x+ 4 | def self.exp10(x) 5 | 10.0 ** x 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/core/facets/hash/delete_at.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # Polymorphic with Array#delete_at. 4 | alias_method :delete_at, :delete 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /lib/standard/facets/math/asec.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Arcus secans of +x+ 4 | def self.asec(x) 5 | acos(1.0 / x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/cot.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Cotangens of +x+ 4 | def self.cot(x) 5 | tan((PI * 0.5) - x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/exists.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # Pluralized alias for `#exist?` method. 4 | alias :exists? :exist? 5 | 6 | end 7 | -------------------------------------------------------------------------------- /lib/standard/facets/yaml.rb: -------------------------------------------------------------------------------- 1 | require 'yaml' 2 | 3 | require 'facets/yaml/file' 4 | require 'facets/yaml/read' 5 | require 'facets/yaml/kernel' 6 | 7 | -------------------------------------------------------------------------------- /demo/core/facets.md: -------------------------------------------------------------------------------- 1 | # Requiring Facets 2 | 3 | We should be able to require all the core libraries by simply calling, 4 | 5 | require 'facets' 6 | 7 | -------------------------------------------------------------------------------- /lib/standard/facets/math/root.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # The `y` root of `x`. 4 | def self.root(x, y) 5 | x ** (1.0 / y) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/sech.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Secans hyperbolicus of +x+ 4 | def self.sech(x) 5 | 1.0 / cosh(x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /demo/core/string/op_sub.md: -------------------------------------------------------------------------------- 1 | ## String#- 2 | 3 | require 'facets/string/op_sub' 4 | 5 | s = "xxbooxxfoo" 6 | (s - "xx").assert == "boofoo" 7 | 8 | -------------------------------------------------------------------------------- /lib/core/facets/hash/at.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # Alias for fetch for greater polymorphism with Array. 4 | # 5 | alias_method :at, :[] 6 | 7 | end 8 | 9 | -------------------------------------------------------------------------------- /lib/core/facets/string/indexable.rb: -------------------------------------------------------------------------------- 1 | require 'facets/indexable' 2 | require 'facets/string/splice' 3 | 4 | class String 5 | include Indexable 6 | end 7 | 8 | -------------------------------------------------------------------------------- /lib/standard/facets/math/acot.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Arcus cotangens of +x+ 4 | def self.acot(x) 5 | (PI * 0.5) - atan(x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/ceil.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Smallest integer not smaller than +x+. 4 | def self.ceil(x) 5 | x.ceil 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/coth.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Cotangens hyperbolicus of +x+ 4 | def self.coth(x) 5 | 1.0 / tanh(x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/math/floor.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Largest integer not larger than +x+. 4 | def self.floor(x) 5 | x.floor 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /demo/core/integer/length.md: -------------------------------------------------------------------------------- 1 | ## Numeric#length 2 | 3 | require 'facets/numeric/length' 4 | 5 | 10.length.assert == 10 6 | 10.0.length.assert == 10 7 | 8 | -------------------------------------------------------------------------------- /demo/core/string/variablize.md: -------------------------------------------------------------------------------- 1 | ## String#variablize 2 | 3 | require 'facets/string/variablize' 4 | 5 | s = "a" 6 | s.variablize.assert == "@a" 7 | 8 | -------------------------------------------------------------------------------- /lib/core/facets/binding/op.rb: -------------------------------------------------------------------------------- 1 | # This file is here for backward compatibility only. 2 | # It can be deprecated eventually. 3 | 4 | require 'facets/binding/op_get' 5 | -------------------------------------------------------------------------------- /lib/core/facets/enumerable/associate.rb: -------------------------------------------------------------------------------- 1 | require 'facets/enumerable/pair' 2 | 3 | module Enumerable 4 | # Alias for #pair. 5 | alias :associate :pair 6 | end 7 | -------------------------------------------------------------------------------- /lib/core/facets/exception.rb: -------------------------------------------------------------------------------- 1 | require_relative 'exception/detail.rb' 2 | require_relative 'exception/raised.rb' 3 | require_relative 'exception/suppress.rb' 4 | 5 | -------------------------------------------------------------------------------- /lib/core/facets/file/atomic_id.rb: -------------------------------------------------------------------------------- 1 | class File 2 | 3 | # 4 | def self.atomic_id 5 | @atomic_id ||= 0 6 | @atomic_id += 1 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /lib/standard/facets/math/sinc.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Sinc function of +x+. 4 | def self.sinc(x) 5 | (x == 0.0) ? 1.0 : sin(x) / x 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/ostruct/to_h.rb: -------------------------------------------------------------------------------- 1 | require 'ostruct' 2 | 3 | class OpenStruct 4 | 5 | # 6 | def to_h 7 | @table.dup 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /work/trash/site/.rsync-filter: -------------------------------------------------------------------------------- 1 | - .svn 2 | - apiwiki 3 | - sitemap.yaml 4 | - scrap 5 | P wiki 6 | P robot.txt 7 | P statcvs 8 | P statsvn 9 | P usage 10 | 11 | -------------------------------------------------------------------------------- /lib/standard/facets/math/round.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Round number to an integer. 4 | # 5 | def self.round(x) 6 | x.round 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /lib/core/facets/array/delete.rb: -------------------------------------------------------------------------------- 1 | # Here for backward compatability. To be deprecated. 2 | require 'facets/array/delete_unless' 3 | require 'facets/array/delete_values' 4 | 5 | -------------------------------------------------------------------------------- /test/core/kernel/test_ask.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/ask' 2 | 3 | test_case Kernel do 4 | 5 | # requires user input 6 | method :ask do 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /work/reference/tmatrix.rb: -------------------------------------------------------------------------------- 1 | require 'matrix.rb' 2 | 3 | class StickMatrix < Matrix 4 | end 5 | 6 | sm = StickMatrix[[0,1,0]] 7 | cl = sm.clone 8 | p cl.class 9 | 10 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/case.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | def case?(*matchers) 4 | matchers.all?{ |m| m === self } 5 | end unless method_defined?(:case?) 6 | 7 | end 8 | 9 | -------------------------------------------------------------------------------- /lib/core/facets/proc/update.rb: -------------------------------------------------------------------------------- 1 | class Proc 2 | 3 | # Use a Proc as an observable. 4 | # 5 | # CREDIT: Tim Pease 6 | 7 | alias_method :update, :call 8 | 9 | end 10 | -------------------------------------------------------------------------------- /lib/core/facets/string/exclude.rb: -------------------------------------------------------------------------------- 1 | class String 2 | 3 | # The inverse of include?. 4 | # 5 | def exclude?(str) 6 | !include?(str) 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/standard/facets/math/asech.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Area secans hyperbolicus of +x+ 4 | def asech(x) 5 | log((1.0 + sqrt(1.0 - x * x)) / x) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /work/OLD_COMPARE/facets/string/at.rb: -------------------------------------------------------------------------------- 1 | 2 | class String 3 | 4 | # Alias for slice which increases polymorphism 5 | # with Array. 6 | alias_method :at, :slice 7 | 8 | end 9 | -------------------------------------------------------------------------------- /demo/core/matchdata/match.md: -------------------------------------------------------------------------------- 1 | ## MatchData#match 2 | 3 | require 'facets/matchdata/match' 4 | 5 | md = /X(a)(b)(c)X/.match("YXabcXY") 6 | md.match.assert == "XabcX" 7 | 8 | -------------------------------------------------------------------------------- /lib/core/facets/numeric/length.rb: -------------------------------------------------------------------------------- 1 | class Numeric 2 | 3 | # Returns +self+, useful for polymorphic cases. 4 | # 5 | def length 6 | self 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/standard/facets/math/acoth.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Area cotangens hyperbolicus of +x+ 4 | def self.acoth(x) 5 | 0.5 * log((x + 1.0) / (x - 1.0)) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/core/facets/hash/delete.rb: -------------------------------------------------------------------------------- 1 | # TODO: should we deprecate hash/delete? 2 | require 'facets/hash/delete_at' 3 | require 'facets/hash/delete_values' 4 | require 'facets/hash/delete_unless' 5 | -------------------------------------------------------------------------------- /work/consider/standard/math/finance.rb: -------------------------------------------------------------------------------- 1 | module Math #:nodoc: 2 | 3 | # TODO 4 | module Finance 5 | 6 | end 7 | 8 | include Finance 9 | extend Finance 10 | end 11 | 12 | -------------------------------------------------------------------------------- /demo/core/array/not_empty.md: -------------------------------------------------------------------------------- 1 | ## Array#not_empty? 2 | 3 | require 'facets/array/not_empty' 4 | 5 | Array is not empty? 6 | 7 | [1,2].assert.not_empty? 8 | [].refute.not_empty? 9 | -------------------------------------------------------------------------------- /demo/core/array/zip.md: -------------------------------------------------------------------------------- 1 | ## Array::zip 2 | 3 | require 'facets/array/zip' 4 | 5 | Class level rendition of Array#zip 6 | 7 | Array.zip([1,2], [3,4]).assert == [[1,3],[2,4]] 8 | 9 | -------------------------------------------------------------------------------- /demo/core/string/titlecase.md: -------------------------------------------------------------------------------- 1 | ## String#titlecase 2 | 3 | require 'facets/string/titlecase' 4 | 5 | r = "try this out".titlecase 6 | x = "Try This Out" 7 | r.assert == x 8 | 9 | -------------------------------------------------------------------------------- /lib/core/facets/array/each_value.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | # Alias for #each. The intention of this method 3 | # is to provide polymorphism with Hash. 4 | alias :each_value :each 5 | end 6 | 7 | -------------------------------------------------------------------------------- /lib/core/facets/hash/op_add.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # Operator for #merge. 4 | # 5 | # CREDIT: Trans 6 | 7 | def +(other) 8 | merge(other) 9 | end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /work/trash/site-jekyll/_config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | source : . 3 | destination : output-sample 4 | markdown : rdiscount 5 | pygments : true 6 | url : http://rubyworks.github.com/facets 7 | -------------------------------------------------------------------------------- /demo/core/string/interpolate.md: -------------------------------------------------------------------------------- 1 | ## String#interpolate 2 | 3 | require 'facets/string/interpolate' 4 | 5 | a = 1 6 | 7 | String.interpolate{ 'this is #{a}' }.assert == 'this is 1' 8 | 9 | -------------------------------------------------------------------------------- /lib/core/facets/exception/set_message.rb: -------------------------------------------------------------------------------- 1 | class Exception 2 | 3 | # See exception message. 4 | # 5 | def set_message(string) 6 | @mesg = string.to_s 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/standard/facets/math/acsch.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Area cosecans hyperbolicus of +x+ 4 | def acsch(x) 5 | ::Math.log(1.0 / x + Math.sqrt(1.0 + 1.0 / (x * x))) 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --title "Ruby Facets" 2 | --readme README.rdoc 3 | --protected 4 | --private 5 | --tag uncommon:Uncommon 6 | --tag standard:Standard 7 | lib/core 8 | lib/standard 9 | - 10 | [A-Z]*.* 11 | -------------------------------------------------------------------------------- /demo/core/string/store.md: -------------------------------------------------------------------------------- 1 | ## String#store 2 | 3 | require 'facets/string/store' 4 | 5 | Alias for []= 6 | 7 | a = "HELLO" 8 | a.store(1, "X") 9 | a.assert == "HXLLO" 10 | 11 | -------------------------------------------------------------------------------- /lib/core/facets/hash/op_or.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # Operator for #reverse_merge. 4 | # 5 | # CREDIT: Trans 6 | 7 | def |(other) 8 | other.merge(self) 9 | end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /demo/core/binding/defined.md: -------------------------------------------------------------------------------- 1 | ## Binding#defined? 2 | 3 | require 'facets/binding/defined' 4 | 5 | a = 1 6 | b = 2 7 | x = "hello" 8 | 9 | binding.assert.defined?("x") 10 | 11 | -------------------------------------------------------------------------------- /demo/core/string/xor.md: -------------------------------------------------------------------------------- 1 | ## String#^ 2 | 3 | require 'facets/string/xor' 4 | 5 | r = "try this out" ^ "puddingsnacks" 6 | x = "\004\a\035D\035\006\016\000N\016\026\037" 7 | r.assert == x 8 | 9 | -------------------------------------------------------------------------------- /lib/core/facets/method.rb: -------------------------------------------------------------------------------- 1 | require_relative 'method/composition.rb' 2 | #require_relative 'method/memoize' # uncommon 3 | require_relative 'method/op_mul.rb' 4 | require_relative 'method/op_pow.rb' 5 | 6 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/rootname.rb: -------------------------------------------------------------------------------- 1 | require 'facets/file/rootname' 2 | 3 | class Pathname 4 | 5 | # 6 | def rootname 7 | self.class.new(File.rootname(to_s)) 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /test/core/kernel/test_d.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/d' 2 | 3 | test_case Kernel do 4 | 5 | # TODO: how to test #d silently? Need to redirect $stderr. 6 | 7 | method :d do 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /test/core/kernel/test_maybe.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/maybe' 2 | 3 | test_case Kernel do 4 | 5 | method :maybe do 6 | 7 | test do 8 | maybe 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /work/rejected/hash/op_div.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # Use division operator as a fetch notation. 4 | # 5 | # h = {:a=>1} 6 | # h/:a #=> 1 7 | 8 | alias_method :/, :[] 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .rbx/ 2 | .rdoc/ 3 | .yardoc/ 4 | log/ 5 | doc/ 6 | pkg/ 7 | tmp/ 8 | web/ 9 | work/rails 10 | work/sandbox 11 | work/trash 12 | Gemfile.lock 13 | .rvmrc 14 | *.gem 15 | .bundle/ 16 | vendor/ 17 | -------------------------------------------------------------------------------- /demo/core/string/line_wrap.md: -------------------------------------------------------------------------------- 1 | ## String#line_wrap 2 | 3 | require 'facets/string/line_wrap' 4 | 5 | "abc123".line_wrap(3).assert == "abc\n123\n" 6 | "abcd123".line_wrap(4).assert == "abcd\n123\n" 7 | 8 | -------------------------------------------------------------------------------- /lib/standard/facets/ostruct/each.rb: -------------------------------------------------------------------------------- 1 | require 'ostruct' 2 | 3 | class OpenStruct 4 | 5 | # Iterate over key-value pairs. 6 | # 7 | def each(&blk) 8 | @table.each(&blk) 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /test/core/kernel/test_require_all.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/require_all' 2 | 3 | test_case Kernel do 4 | 5 | method :require_all do 6 | end 7 | 8 | method :load_all do 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /lib/standard/facets/math/tgamma.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/lgamma' 2 | 3 | module Math 4 | 5 | # Exp of LGamma. 6 | def self.tgamma(x) 7 | exp(lngamma(x)) #exp(log(gamma(x).abs) 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /demo/core/array/contains.md: -------------------------------------------------------------------------------- 1 | ## Array#contains? 2 | 3 | _alias of Array#include? _ 4 | 5 | require 'facets/array/contains' 6 | 7 | [1,2,3,4].assert.contains?(2) 8 | [1,2,3,4].refute.contains?(9) 9 | 10 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/here.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | # A shorthand pronoun for binding(). 4 | # 5 | # a = 3 6 | # eval("a", here) #=> 3 7 | # 8 | alias_method :here, :binding 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/split_root.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # 4 | def split_root 5 | head, tail = *::File.split_root(to_s) 6 | [self.class.new(head), self.class.new(tail)] 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /test/core/file/test_null.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/file/null' 2 | 3 | test_case File do 4 | 5 | class_method :null do 6 | 7 | test do 8 | assert File.null 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /work/consider/core/object/class_def.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | 3 | # Defines an instance method within a class. 4 | def class_def name, &blk 5 | class_eval { define_method name, &blk } 6 | end 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /lib/core/facets/hash/op.rb: -------------------------------------------------------------------------------- 1 | require 'facets/hash/op_and' 2 | require 'facets/hash/op_or' 3 | require 'facets/hash/op_add' 4 | require 'facets/hash/op_sub' 5 | require 'facets/hash/op_mul' 6 | require 'facets/hash/op_push' 7 | 8 | -------------------------------------------------------------------------------- /lib/core/facets/regexp.rb: -------------------------------------------------------------------------------- 1 | require_relative 'regexp/arity.rb' 2 | require_relative 'regexp/multiline.rb' 3 | require_relative 'regexp/op_add.rb' 4 | require_relative 'regexp/op_or.rb' 5 | require_relative 'regexp/to_re.rb' 6 | 7 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/empty.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # Is a directory path empty? 4 | # 5 | # Returns [Boolean] 6 | def empty? 7 | Dir.glob(::File.join(to_s, '*')).empty? 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /test/core/kernel/test_here.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/here' 2 | 3 | test_case Kernel do 4 | 5 | method :here do 6 | 7 | test do 8 | here.assert.is_a?(Binding) 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /demo/core/array/store.md: -------------------------------------------------------------------------------- 1 | ## Array#store 2 | 3 | require 'facets/array/store' 4 | 5 | Store a value at a given index. Store is an alias for #[]= 6 | 7 | a = [] 8 | a.store(1,"A") 9 | a[1].assert == "A" 10 | -------------------------------------------------------------------------------- /lib/core/facets/method/partial.rb: -------------------------------------------------------------------------------- 1 | require 'facets/proc/partial' 2 | 3 | class Method 4 | # Convert a method into a new partial Proc. 5 | 6 | def partial(*args) 7 | to_proc.partial(*args) 8 | end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/core/facets/struct/replace.rb: -------------------------------------------------------------------------------- 1 | class Struct 2 | 3 | # Struct#replace can take any +source+ that responds to #each_pair. 4 | def replace(source) 5 | source.each_pair{ |k,v| send(k.to_s + "=", v) } 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/to_str.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # Alias #to_s to #to_str when #to_str is not defined. 4 | # 5 | # Returns [String] 6 | alias_method(:to_str, :to_s) unless method_defined?(:to_str) 7 | 8 | end 9 | -------------------------------------------------------------------------------- /demo/core/string/rewrite.md: -------------------------------------------------------------------------------- 1 | ## String#rewrite 2 | 3 | require 'facets/string/rewrite' 4 | 5 | s = "HELLO TOMMY!" 6 | rules = [[ /TOMMY/, 'MAN' ]] 7 | r = s.rewrite(rules) 8 | r.assert == "HELLO MAN!" 9 | 10 | -------------------------------------------------------------------------------- /demo/core/string/subtract.md: -------------------------------------------------------------------------------- 1 | ## String#- 2 | 3 | require 'facets/string/subtract' 4 | 5 | ("foobar" - "oo").assert == "fbar" 6 | ("pizza pizza!" - "zz").assert == "pia pia!" 7 | ("letters" - /[a-z]+/).assert == "" 8 | 9 | -------------------------------------------------------------------------------- /lib/core/facets/array/not_empty.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | 3 | # Not empty? 4 | # 5 | # [].not_empty? #=> false 6 | # [1,2].not_empty? #=> true 7 | 8 | def not_empty? 9 | !empty? 10 | end 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /lib/core/facets/hash/update.rb: -------------------------------------------------------------------------------- 1 | # -- for backward compatibility. To be deprecated. 2 | require 'facets/hash/op_push' 3 | require 'facets/hash/update_each' 4 | require 'facets/hash/update_keys' 5 | require 'facets/hash/update_values' 6 | 7 | -------------------------------------------------------------------------------- /lib/standard/facets/math/csc.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Cosecans of `x`. 4 | def self.csc(x) 5 | 1.0 / sin(x) 6 | end 7 | 8 | # Cosecans of `x`. 9 | def self.cosec(x) 10 | 1.0 / sin(x) 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /demo/core/array/only.md: -------------------------------------------------------------------------------- 1 | ## Array#only 2 | 3 | require 'facets/array/only' 4 | 5 | [5].only.assert == 5 6 | [nil].only.assert == nil 7 | expect(IndexError){ [].only } 8 | expect(IndexError){ [1,2,3].only } 9 | 10 | -------------------------------------------------------------------------------- /demo/core/integer/times_collect.md: -------------------------------------------------------------------------------- 1 | ## Integer#times_collect 2 | 3 | require 'facets/integer/of' 4 | 5 | a = 4 6 | b = a.times_collect{ |i| i*2 } 7 | b.assert == [0,2,4,6] 8 | 9 | See `Integer#of` which is an alias. 10 | -------------------------------------------------------------------------------- /lib/core/facets/string/acronym.rb: -------------------------------------------------------------------------------- 1 | class String 2 | 3 | # Transform a string into an acronym. 4 | # 5 | # CREDIT: Robert Fey 6 | # 7 | def acronym 8 | gsub(/(([a-zA-Z0-9])([a-zA-Z0-9])*)./,"\\2") 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /lib/standard/facets/math/pow.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # `x` to the power `y`. 4 | def self.pow(x, y) 5 | x ** y 6 | end 7 | 8 | # `x` to the power `y`. 9 | def self.pwr(x, y) 10 | x ** y 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/root.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # Root constant for building paths from root directory onward. 4 | # 5 | # Returns [Pathname] 6 | def self.root 7 | Pathname.new('/') 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/work.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # Work constant for building paths from root directory onward. 4 | # 5 | # Returns [Pathname] 6 | def self.work 7 | Pathname.new('.') 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /test/core/filetest/test_root.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/filetest/root' 2 | 3 | test_case FileTest do 4 | 5 | class_method :root? do 6 | 7 | test do 8 | assert FileTest.root?('/') 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /test/core/string/test_unquote.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/string/unquote' 2 | 3 | test_case String do 4 | 5 | method :unquote do 6 | 7 | test do 8 | "'here'".unquote.assert == "here" 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/extension.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | # TODO: Must reduce the number of singleton method methods. 4 | 5 | # Don't say it! 6 | # 7 | def extension 8 | class << self; self; end 9 | end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /lib/core/facets/metaid.rb: -------------------------------------------------------------------------------- 1 | require 'facets/kernel/meta_alias' 2 | require 'facets/kernel/meta_class' 3 | require 'facets/kernel/meta_def' 4 | require 'facets/kernel/meta_eval' 5 | 6 | # in remberence of _why 7 | require 'facets/kernel/eigenclass' 8 | -------------------------------------------------------------------------------- /lib/core/facets/module/alias_class_method.rb: -------------------------------------------------------------------------------- 1 | class Module 2 | 3 | # Alias a class method. 4 | # 5 | def alias_class_method(name, target) 6 | class << self 7 | alias_method(name, target) 8 | end 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /lib/standard/facets/yaml/read.rb: -------------------------------------------------------------------------------- 1 | module YAML 2 | 3 | # Alias for `YAML.load_file` and the same as: 4 | # 5 | # YAML.load(File.new(file)) 6 | # 7 | def self.read(file) 8 | load(File.new(file)) 9 | end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /test/core/dir/test_parent.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/dir/parent' 2 | 3 | test_case Dir do 4 | 5 | class_method :parent? do 6 | 7 | test do 8 | Dir.assert.parent?("a/b/c", "a/b/c/d") 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /test/core/module/test_modname.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/module/modname' 2 | 3 | test_case Module do 4 | 5 | method :modname do 6 | 7 | test do 8 | Lemon::TestCase.modname.assert == "Lemon" 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /demo/core/matchdata/matchset.md: -------------------------------------------------------------------------------- 1 | ## MatchData#matchset 2 | 3 | require 'facets/matchdata/matchset' 4 | 5 | md = /(bb)(cc(dd))(ee)/.match "XXaabbccddeeffXX" 6 | md.matchset.assert == ["XXaa", [["bb"], ["cc", ["dd"]], ["ee"]], "ffXX"] 7 | 8 | -------------------------------------------------------------------------------- /demo/core/string/each_word.md: -------------------------------------------------------------------------------- 1 | ## String#each_word 2 | 3 | require 'facets/string/each_word' 4 | 5 | a = [] 6 | i = "this is a test" 7 | 8 | i.each_word{ |w| a << w } 9 | 10 | a.assert == ['this', 'is', 'a', 'test'] 11 | 12 | -------------------------------------------------------------------------------- /lib/core/facets/dir.rb: -------------------------------------------------------------------------------- 1 | require_relative 'dir/ascend.rb' 2 | require_relative 'dir/descend.rb' 3 | require_relative 'dir/each_child.rb' 4 | require_relative 'dir/multiglob.rb' 5 | require_relative 'dir/parent.rb' 6 | require_relative 'dir/recurse.rb' 7 | 8 | -------------------------------------------------------------------------------- /test/core/array/test_zip.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/array/zip' 2 | 3 | test_case Array do 4 | 5 | method :zip do 6 | 7 | test 'example' do 8 | Array.zip([1,2], [3,4]).assert == [[1,3],[2,4]] 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /test/core/kernel/test_in.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/in' 2 | 3 | test_case Kernel do 4 | 5 | method :in? do 6 | 7 | test do 8 | 5.assert.in?(0..10) 9 | 5.assert.in?([1,2,3,4,5]) 10 | end 11 | 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /demo/core/string/divide.md: -------------------------------------------------------------------------------- 1 | ## String#divide 2 | 3 | require 'facets/string/divide' 4 | 5 | s = "
Thisisa test.
" 6 | d = s.divide(/<.*?>/) 7 | e = ["This", "is", "a test.", "
"] 8 | d.assert == e 9 | 10 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/object_class.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | # Defines object_classas an alias of class. 4 | # This is an alternative to __class__, akin to 5 | # #object_id. 6 | 7 | alias_method :object_class, :class 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/core/facets/proc.rb: -------------------------------------------------------------------------------- 1 | require_relative 'proc/bind.rb' 2 | require_relative 'proc/bind_to.rb' 3 | require_relative 'proc/compose.rb' 4 | require_relative 'proc/partial.rb' 5 | require_relative 'proc/to_method.rb' 6 | require_relative 'proc/update.rb' 7 | 8 | -------------------------------------------------------------------------------- /lib/standard/facets/cgi/esc.rb: -------------------------------------------------------------------------------- 1 | require 'facets/cgi/escape_html' 2 | 3 | class CGI 4 | 5 | # Instance level method for {CGI::escape_html}. 6 | 7 | def esc(string, *modes) 8 | self.class.escape_html(string, *modes) 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /lib/standard/facets/math/acsc.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Arcus cosecans of `x`. 4 | def self.acsc(x) 5 | asin(1.0 / x) 6 | end 7 | 8 | # Arcus cosecans of `x`. 9 | def self.acosec(x) 10 | asin(1.0 / x) 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /lib/standard/facets/math/delta.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Kronecker symbol of +i+ and +j+. 4 | # Returns 1 if +i+ and +j+ are equal, 0 otherwise. 5 | def self.delta(i, j) 6 | return Integer(i) == Integer(j) ? 1 : 0 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /lib/standard/facets/pathname/op_fetch.rb: -------------------------------------------------------------------------------- 1 | class Pathname 2 | 3 | # Alternate to Pathname#new. 4 | # 5 | # Pathname['/usr/share'] 6 | # 7 | # Returns [Pathname] 8 | 9 | def self.[](path) 10 | new(path) 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /test/core/array/test_op_pow.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/array/op_pow' 2 | 3 | test_case Array do 4 | 5 | method :** do 6 | 7 | test do 8 | ([1,2] ** [3,4]).assert == [[1, 3], [1, 4], [2, 3], [2, 4]] 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /test/core/file/test_rootname.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/file/rootname' 2 | 3 | test_case File do 4 | 5 | class_method :rootname do 6 | 7 | test do 8 | File.rootname('test/core/file').assert == 'test' 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /test/core/symbol/test_as_s.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/symbol/as_s' 2 | 3 | test_case Symbol do 4 | 5 | method :as_s do 6 | 7 | test do 8 | s = :foo.as_s.sub('f','g') 9 | s.assert == :goo 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /test/core/symbol/test_variablize.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/symbol/variablize' 2 | 3 | test_case Symbol do 4 | 5 | method :variablize do 6 | 7 | test do 8 | :a.variablize.assert == "@a".to_sym 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /lib/core/facets/file/append.rb: -------------------------------------------------------------------------------- 1 | class File 2 | 3 | # Append to a file. 4 | # 5 | # CREDIT: George Moschovitis 6 | 7 | def self.append(file, str) 8 | File.open(file, 'ab') { |f| 9 | f << str 10 | } 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /lib/core/facets/module/class.rb: -------------------------------------------------------------------------------- 1 | class Module 2 | 3 | # Alias for #===. This provides a verbal method 4 | # for inquery. 5 | # 6 | # s = "HELLO" 7 | # String.class?(s) #=> true 8 | # 9 | alias_method :class?, :=== 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /test/core/module/test_basename.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/module/basename' 2 | 3 | test_case Module do 4 | 5 | method :basename do 6 | 7 | test do 8 | Lemon::TestCase.basename.assert == "TestCase" 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /test/core/regexp/test_op_add.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/regexp/op_add' 2 | 3 | test_case Regexp do 4 | 5 | method :+ do 6 | 7 | test do 8 | r = /a/ + /b/ 9 | r.assert == /(?-mix:a)(?-mix:b)/ 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /test/core/string/test_cleanlines.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/string/cleanlines' 2 | 3 | test_case String do 4 | 5 | method :cleanlines do 6 | test do 7 | "a \n b \nc".cleanlines.to_a.assert == ["a","b","c"] 8 | end 9 | end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /test/core/time/test_to_time.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/time/to_time' 2 | 3 | test_case Time do 4 | 5 | method :to_time do 6 | 7 | test do 8 | t = Time.now 9 | t.to_time.assert.is_a?(Time) 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /demo/core/array/last.md: -------------------------------------------------------------------------------- 1 | ## Array#last! 2 | 3 | require 'facets/array/indexable' 4 | 5 | Alias for pop, which removes and returns the last element in an 6 | array. 7 | 8 | a = [1,2,3] 9 | a.last!.assert == 3 10 | a.assert == [1,2] 11 | -------------------------------------------------------------------------------- /demo/core/integer/of.md: -------------------------------------------------------------------------------- 1 | ## Integer#of 2 | 3 | require 'facets/integer/of' 4 | 5 | Similar to `Enumerable#map` and `Enumerable#collect` but for a number 6 | of times. 7 | 8 | a = 4 9 | b = a.of{ |i| i*2 } 10 | b.assert == [0,2,4,6] 11 | 12 | -------------------------------------------------------------------------------- /demo/core/string/lowercase.md: -------------------------------------------------------------------------------- 1 | ## String#lowercase 2 | 3 | require 'facets/string/lowercase' 4 | 5 | Downcase the first letter. 6 | 7 | s = 'Abc' 8 | s.lowercase.assert == 'abc' 9 | 10 | s = 'ABC' 11 | s.lowercase.assert == 'aBC' 12 | 13 | -------------------------------------------------------------------------------- /demo/core/string/unfold.md: -------------------------------------------------------------------------------- 1 | ## String#unfold 2 | 3 | require 'facets/string/unfold' 4 | 5 | str = "This is a test of\nparagraph folding." 6 | res = str.unfold 7 | exp = "This is a test of paragraph folding." 8 | res.assert == exp 9 | 10 | -------------------------------------------------------------------------------- /lib/core/facets/binding/defined.rb: -------------------------------------------------------------------------------- 1 | class Binding 2 | 3 | # Returns the nature of something within the context of the binding. 4 | # Returns nil if that thing is not defined. 5 | def defined?(x) 6 | eval("defined? #{x}") 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/in.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | # Is self included in other? 4 | # 5 | # 5.in?(0..10) #=> true 6 | # 5.in?([0,1,2,3]) #=> false 7 | # 8 | def in?(other) 9 | other.include?(self) 10 | end 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /lib/core/facets/range/overlap.rb: -------------------------------------------------------------------------------- 1 | class Range 2 | 3 | # Do two ranges overlap? 4 | # 5 | # CREDIT: Daniel Schierbeck, Brandon Keepers 6 | 7 | def overlap?(other) 8 | include?(other.first) or other.include?(first) 9 | end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /lib/standard/facets/math/csch.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Cosecans hyperbolicus of `x`. 4 | def self.csch(x) 5 | 1.0 / sinh(x) 6 | end 7 | 8 | # Cosecans hyperbolicus of `x`. 9 | def self.cosech(x) 10 | 1.0 / sinh(x) 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /test/core/array/test_pull.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/array/pull' 2 | 3 | test_case Array do 4 | 5 | method :pull do 6 | 7 | test do 8 | a = [1,2,3] 9 | a.pull.assert == 1 10 | a.assert == [2,3] 11 | end 12 | 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /test/core/array/test_to_h.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/array/to_h' 2 | 3 | test_case Array do 4 | 5 | method :to_h do 6 | 7 | test do 8 | arr = [[:a, 1], [:b, 2]] 9 | arr.to_h.assert == {:a => 1, :b => 2} 10 | end 11 | 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /test/core/binding/test_self.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/binding/self' 2 | 3 | test_case Binding do 4 | 5 | bind = binding 6 | this = self 7 | 8 | method :self do 9 | 10 | test do 11 | bind.self == this 12 | end 13 | 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /test/core/kernel/test_class.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/kernel/__class__' 2 | 3 | test_case Kernel do 4 | 5 | method :__class__ do 6 | 7 | test do 8 | o = Object.new 9 | o.__class__.assert == o.class 10 | end 11 | 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /test/core/proc/test_update.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/proc/update' 2 | 3 | test_case Proc do 4 | 5 | method :update do 6 | 7 | test do 8 | p1 = Proc.new{ 'here' } 9 | p1.update.assert == 'here' 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /test/core/string/test_op_sub.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/string/op_sub' 2 | 3 | test_case String do 4 | 5 | method :"-" do 6 | 7 | test do 8 | s = "xxbooxxfoo" 9 | (s - "xx").assert == "boofoo" 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /test/core/string/test_variablize.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/string/variablize' 2 | 3 | test_case String do 4 | 5 | method :variablize do 6 | 7 | test do 8 | s = "a" 9 | s.variablize.assert == "@a" 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /demo/core/array/delete_values.md: -------------------------------------------------------------------------------- 1 | ## Array#delete_values 2 | 3 | require 'facets/array/delete_values' 4 | 5 | Delete multiple values from array. 6 | 7 | a = [1,2,3,4] 8 | a.delete_values(1,2) #=> [1,2] 9 | a #=> [3,4] 10 | 11 | -------------------------------------------------------------------------------- /demo/core/string/acronym.md: -------------------------------------------------------------------------------- 1 | ## String#acronym 2 | 3 | require 'facets/string/acronym' 4 | 5 | Transform a string into an acronym. 6 | 7 | 'abc'.acronym.assert == 'a' 8 | 'abc def'.acronym.assert == 'ad' 9 | 'abc def ghi'.acronym.assert == 'adg' 10 | -------------------------------------------------------------------------------- /lib/core/facets/numeric/positive.rb: -------------------------------------------------------------------------------- 1 | class Numeric 2 | 3 | # Is a number greater than zero. 4 | # 5 | def positive? 6 | self > 0 7 | end 8 | 9 | # Is a number less than zero. 10 | # 11 | def negative? 12 | self < 0 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /test/core/hash/test_swap.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/hash/swap' 2 | 3 | test_case Hash do 4 | 5 | method :swap! do 6 | 7 | test do 8 | h = { :a=>1, :b=>2 } 9 | h.swap!(:a, :b).assert == { :a=>2, :b=>1 } 10 | end 11 | 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /test/core/regexp/test_op_or.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/regexp/op_or' 2 | 3 | test_case Regexp do 4 | 5 | method :| do 6 | 7 | test do 8 | re = /a/ | /b/ 9 | re.assert =~ "a" 10 | re.assert =~ "b" 11 | end 12 | 13 | end 14 | 15 | end 16 | 17 | -------------------------------------------------------------------------------- /test/core/symbol/test_bang.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/symbol/bang' 2 | 3 | test_case Symbol do 4 | 5 | method :bang? do 6 | 7 | test do 8 | :a.refute.bang? 9 | :a?.refute.bang? 10 | :a!.assert.bang? 11 | end 12 | 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /demo/core/string/shatter.md: -------------------------------------------------------------------------------- 1 | ## String#shatter 2 | 3 | require 'facets/string/shatter' 4 | 5 | s = "Thisisa test.
" 6 | r = s.shatter( /<.*?>/ ) 7 | x = ["", "This", "", "is", "", "a test.", "
"] 8 | r.assert == x 9 | 10 | -------------------------------------------------------------------------------- /lib/core/facets/exception/raised.rb: -------------------------------------------------------------------------------- 1 | class Exception 2 | 3 | # Does a block raise an a given +exception+. 4 | # 5 | def self.raised? #:yeild: 6 | begin 7 | yield 8 | false 9 | rescue self 10 | true 11 | end 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /lib/core/facets/objectspace/classes.rb: -------------------------------------------------------------------------------- 1 | module ObjectSpace 2 | 3 | # @returnThisisa test.
" 9 | d = s.divide( /<.*?>/ ) 10 | e = ["This", "is", "a test.", "
"] 11 | d.assert == e 12 | end 13 | 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /lib/core/facets/enumerable/exclude.rb: -------------------------------------------------------------------------------- 1 | module Enumerable 2 | 3 | unless method_defined?(:exclude?) # 1.9 4 | 5 | # The inverse of #include?. 6 | # 7 | # [:a, :b].exclude?(:c) #=> true 8 | # [:a, :b].exclude?(:a) #=> false 9 | # 10 | def exclude?(object) 11 | !include?(object) 12 | end 13 | 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/standard/facets/math/summed_sqdevs.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/sum' 2 | require 'facets/math/mean' 3 | 4 | module Math 5 | 6 | # The sum of the squared deviations from the mean. 7 | # 8 | def self.summed_sqdevs(array) 9 | return 0 if array.size < 2 10 | m = mean(array) 11 | sum(array.map{ |x| (x - m) ** 2 }) 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /test/core/enumerable/test_per.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/enumerable/per' 2 | 3 | test_case Enumerable do 4 | 5 | method :per do 6 | 7 | test "map" do 8 | e = [1,2,3].per.map 9 | 10 | (e + 3).assert == [4,5,6] 11 | (e - 1).assert == [0,1,2] 12 | 13 | e.to_s.assert == ['1','2','3'] 14 | end 15 | 16 | end 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /test/core/module/test_can.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/module/can' 2 | 3 | test_case Module do 4 | 5 | method :can do 6 | 7 | test do 8 | m = Module.new do 9 | def x; "x"; end 10 | end 11 | 12 | c = Class.new do 13 | can m 14 | end 15 | 16 | c.x.assert == "x" 17 | end 18 | 19 | end 20 | 21 | end 22 | 23 | -------------------------------------------------------------------------------- /test/core/string/test_unfold.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/string/unfold' 2 | 3 | test_case String do 4 | 5 | method :unfold do 6 | 7 | test do 8 | str = "This is a test of\nparagraph folding." 9 | res = str.unfold 10 | exp = "This is a test of paragraph folding." 11 | res.assert == exp 12 | end 13 | 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/core/time/test_change.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/time/change' 2 | 3 | test_case Time do 4 | 5 | method :change do 6 | 7 | test do 8 | t = Time.local(2006,04,20,15,37) 9 | n = Time.now 10 | n = n.change(:month=>4, :day=>20, :hour=>15, :min=>37, :year=>2006) 11 | n.assert == t 12 | end 13 | 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/standard/pathname/test_chdir.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/pathname/chdir' 2 | 3 | test_case Pathname do 4 | 5 | method :chdir do 6 | 7 | test do 8 | Pathname.pwd.basename.to_s.assert != 'tmp' 9 | Pathname.new('tmp').chdir do 10 | Pathname.pwd.basename.to_s.assert == 'tmp' 11 | end 12 | end 13 | 14 | end 15 | end 16 | 17 | -------------------------------------------------------------------------------- /demo/core/array/poke.md: -------------------------------------------------------------------------------- 1 | ## Array#poke 2 | 3 | require 'facets/array/poke' 4 | 5 | Put an object on the bottom of the stack (front of the array). 6 | 7 | a = [2,3] 8 | a.poke(1) 9 | a.assert == [1,2,3] 10 | 11 | Or supply an index and #poke works like insert. 12 | 13 | a = [1,3] 14 | a.poke(2,1) 15 | a.assert == [1,2,3] 16 | -------------------------------------------------------------------------------- /lib/core/facets/array/op_pow.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | # Array#** is an alias for Array#product. 3 | # 4 | # NOTE: This method is not a common core extension and is not 5 | # loaded automatically when usingrequire 'facets'.
6 | #
7 | # @uncommon
8 | # require 'facets/array/op_pow'
9 | #
10 | alias_method :**, :product
11 | end
12 |
13 |
--------------------------------------------------------------------------------
/lib/core/facets/hash/swap.rb:
--------------------------------------------------------------------------------
1 | class Hash
2 |
3 | # Swap the values of a pair of keys in place.
4 | #
5 | # {:a=>1,:b=>2}.swap!(:a,:b) #=> {:a=>2,:b=>1}
6 | #
7 | # CREDIT: Gavin Sinclair
8 |
9 | def swap!(key1, key2)
10 | tmp = self[key1]
11 | self[key1] = self[key2]
12 | self[key2] = tmp
13 | self
14 | end
15 |
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/lib/core/facets/kernel/super_method.rb:
--------------------------------------------------------------------------------
1 | module Kernel
2 |
3 | # Returns method of a parent class bound to self.
4 | def super_method(klass, meth)
5 | unless self.class.ancestors.include?(klass)
6 | raise ArgumentError, "Not an ancestor for super_method-- #{klass}"
7 | end
8 | klass.instance_method(meth).bind(self)
9 | end
10 |
11 | end
12 |
--------------------------------------------------------------------------------
/lib/core/facets/method/curry.rb:
--------------------------------------------------------------------------------
1 | require 'facets/proc'
2 |
3 | class Method
4 | # Curry a Method into a new Proc.
5 |
6 | def curry(*args)
7 | to_proc.curry(*args)
8 | end
9 | end
10 |
11 |
12 | # TODO: The question is as to whether to integrate this into Method::Composition,
13 | # or if Composition should be scuttled for just converting to Proc.
14 |
--------------------------------------------------------------------------------
/test/core/file/test_create.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/file/create'
2 |
3 | test_case File do
4 |
5 | class_method :create do
6 |
7 | test_file = 'tmp/rewrite.txt'
8 | test_data = 'This is a test!'
9 |
10 | test do
11 | File.create(test_file, test_data)
12 | File.read(test_file).assert == test_data
13 | end
14 |
15 | end
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/test/core/hash/test_replace_each.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/hash/replace_each'
2 |
3 | test_case Hash do
4 |
5 | method :replace_each do
6 |
7 | test do
8 | a = { :a => 1, :b => 2, :c => 3 }
9 | x = { :a => 2, :b => 3, :c => 4 }
10 | a.replace_each{ |k,v| { k => v+1 } }
11 | a.assert == x
12 | end
13 |
14 | end
15 |
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/test/core/range/test_to_rng.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/range/to_rng'
2 |
3 | test_case Range do
4 |
5 | method :to_rng do
6 | test do
7 | a = (0..10)
8 | a.to_rng.assert == a
9 | end
10 | end
11 |
12 | method :to_range do
13 | test do
14 | a = (0..10)
15 | a.to_range.assert == a
16 | end
17 | end
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/demo/core/comparable/bound.md:
--------------------------------------------------------------------------------
1 | ## Comparable#bound
2 |
3 | require 'facets/comparable/bound'
4 |
5 | The `#bound` method is an alias for `#clip`. It is the original name
6 | of the method before the `clip`/`cap` duo was decided upon.
7 |
8 | 3.bound(4).assert == 4
9 |
10 | 4.bound(3,5).assert == 4
11 |
12 | 'd'.bound('c','e').assert == 'd'
13 |
14 |
--------------------------------------------------------------------------------
/demo/core/matchdata/matchtree.md:
--------------------------------------------------------------------------------
1 | ## MatchData#matchtree
2 |
3 | require 'facets/matchdata/matchtree'
4 |
5 | md = /(bb)(cc(dd))(ee)/.match "XXaabbccddeeffXX"
6 | md.matchtree.assert == [["bb"], ["cc", ["dd"]], ["ee"]]
7 |
8 | md = /(bb)c(c(dd))(ee)/.match "XXaabbccddeeffXX"
9 | md.matchtree.assert == [["bb"], "c", ["c", ["dd"]], ["ee"]]
10 |
11 |
--------------------------------------------------------------------------------
/lib/core/facets/file/split_root.rb:
--------------------------------------------------------------------------------
1 | class File
2 |
3 | # Return the head of path from the rest of the path.
4 | #
5 | # File.split_root('etc/xdg/gtk') #=> ['etc', 'xdg/gtk']
6 | #
7 | def self.split_root(path)
8 | path_re = Regexp.new('[' + Regexp.escape(File::Separator + %q{\/}) + ']')
9 | path.split(path_re, 2)
10 | end
11 |
12 | end
13 |
14 |
--------------------------------------------------------------------------------
/test/core/array/test_probability.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/probability'
2 |
3 | test_case Array do
4 |
5 | method :probability do
6 |
7 | test do
8 | %w{a b}.probability.assert == {'a'=>0.5, 'b'=>0.5}
9 | end
10 |
11 | test do
12 | %w{a a a b}.probability.assert == {'a'=>0.75, 'b'=>0.25}
13 | end
14 |
15 | end
16 |
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/test/core/hash/test_inverse.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/hash/inverse'
2 |
3 | test_case Hash do
4 |
5 | method :inverse do
6 |
7 | test do
8 | h1 = { :a=>1, :b=>2, :c=>2 }
9 | h2 = h1.inverse
10 |
11 | h2[1].assert == :a
12 |
13 | h2[2].assert.include?(:b)
14 | h2[2].assert.include?(:c)
15 | end
16 |
17 | end
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/test/core/string/test_newlines.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/newlines'
2 |
3 | test_case String do
4 |
5 | # Since Ruby 1.9 defined #lines to keep the newline character,
6 | # we have defined #newlines to leave them out.
7 | method :newlines do
8 | test do
9 | "a\nb\nc".newlines.to_a.assert == ["a","b","c"]
10 | end
11 | end
12 |
13 | end
14 |
15 |
--------------------------------------------------------------------------------
/test/core/string/test_shatter.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/shatter'
2 |
3 | test_case String do
4 |
5 | method :shatter do
6 |
7 | test do
8 | s = "Thisisa test.
" 9 | r = s.shatter( /<.*?>/ ) 10 | x = ["", "This", "", "is", "", "a test.", "
"] 11 | r.assert == x 12 | end 13 | 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /lib/core/facets/array/to_h.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | 3 | # Convert an associative array to a Hash. 4 | # 5 | # Examples 6 | # 7 | # [[:a, 1], [:b, 2]].to_h 8 | # #=> {:a=>1, :b=>2} 9 | # 10 | # Returns [Hash]. 11 | # 12 | def to_h 13 | h = {} 14 | each{ |(k,v)| h[k] = v } 15 | h 16 | end unless method_defined?(:to_h) 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /lib/core/facets/object/itself.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | 3 | # An identity method that provides access to an object's 'self'. 4 | # 5 | # Example 6 | # 7 | # [1,2,3,4,5,1,2,2,3].group_by(&:itself) 8 | # #=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]} 9 | # 10 | # CREDIT: Michael Kohl 11 | 12 | def itself 13 | self 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/core/facets/string/each_word.rb: -------------------------------------------------------------------------------- 1 | require 'facets/string/words' 2 | 3 | class String 4 | 5 | # Iterate through each word of a string. 6 | # 7 | # a = [] 8 | # 9 | # "list of words".each_word { |word| a << word } 10 | # 11 | # a #=> ['list', 'of', 'words'] 12 | # 13 | def each_word(&block) 14 | words.each(&block) 15 | end 16 | 17 | end 18 | -------------------------------------------------------------------------------- /lib/core/facets/symbol/variablize.rb: -------------------------------------------------------------------------------- 1 | class Symbol 2 | 3 | # Prepend an "@" to the beginning of a symbol to make a instance 4 | # variable name. This also replaces non-valid characters with underscores. 5 | # 6 | # :a.variablize #=> :"@a" 7 | # 8 | def variablize 9 | name = to_s.gsub(/\W/, '_') 10 | "@#{name}".to_sym 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /lib/core/facets/time/elapse.rb: -------------------------------------------------------------------------------- 1 | class Time 2 | 3 | # Tracks the elapse time of a code block. 4 | # 5 | # e = Time.elapse { sleep 1 } 6 | # 7 | # e.assert > 1 8 | # 9 | # CREDIT: Hal Fulton 10 | 11 | def self.elapse 12 | raise "Need block" unless block_given? 13 | t0 = now.to_f 14 | yield 15 | now.to_f - t0 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /lib/standard/facets/math/beta.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/tgamma' 2 | 3 | module Math 4 | 5 | # Beta function of `x` and `y`. 6 | # 7 | # beta(x, y) = tgamma(x) * tgamma(y) / tgamma(x + y) 8 | # 9 | def self.beta(x, y) 10 | #exp(lgamma(x).first + lgamma(y).first - lgamma(x+y).first) 11 | tgamma(x) * tgamma(y) / tgamma(x + y) 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /test/core/class/test_descendents.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/class/descendants' 2 | 3 | test_case Class do 4 | 5 | method :descendants do 6 | 7 | a = Class.new 8 | b = Class.new(a) 9 | c = Class.new(b) 10 | 11 | test do 12 | a.descendants.assert.include?(b) 13 | a.descendants.assert.include?(c) 14 | end 15 | 16 | end 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /test/core/hash/test_delete_unless.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/hash/delete_unless' 2 | 3 | test_case Hash do 4 | 5 | method :delete_unless do 6 | 7 | test do 8 | a = { :a => 1, :b => 2, :c => 3 } 9 | x = { :a => 1 } 10 | r = a.delete_unless{|k,v| v == 1} 11 | r.assert == x 12 | a.assert == x 13 | end 14 | 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /test/core/module/test_to_obj.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/module/to_obj' 2 | 3 | test_case Module do 4 | 5 | method :to_obj do 6 | 7 | test do 8 | m = Module.new do 9 | def x; "x"; end 10 | def y; "y"; end 11 | end 12 | o = m.to_obj 13 | o.x.assert == "x" 14 | o.y.assert == "y" 15 | end 16 | 17 | end 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /demo/core/array/entropy.md: -------------------------------------------------------------------------------- 1 | ## Array#entropy 2 | 3 | require 'facets/array/entropy' 4 | 5 | Shannon's entropy for an array - returns the average 6 | bits per symbol required to encode the array. 7 | Lower values mean less "entropy" - i.e. less unique 8 | information in the array. 9 | 10 | e = %w{ a b c d e e e }.entropy 11 | 12 | ("%.3f" % e) #=> "2.128" 13 | 14 | -------------------------------------------------------------------------------- /lib/core/facets/array/average.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | 3 | # Calculate the average of an array of numbers 4 | # 5 | # Examples 6 | # 7 | # [].average #=> nil 8 | # [1, 2, 3].average #=> 2 9 | # [3, 12, 57, 85, 15, 89, 33, 7, 22, 54].average #=> 37.7 10 | # 11 | def average 12 | return nil if empty? 13 | self.reduce(:+)/length.to_f 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/core/facets/file/null.rb: -------------------------------------------------------------------------------- 1 | class File 2 | 3 | # Platform dependent null device. 4 | # 5 | # CREDIT: Daniel Burger 6 | 7 | def self.null 8 | case RUBY_PLATFORM 9 | when /mswin/i 10 | 'NUL' 11 | when /amiga/i 12 | 'NIL:' 13 | when /openvms/i 14 | 'NL:' 15 | else 16 | '/dev/null' 17 | end 18 | end 19 | 20 | end 21 | 22 | -------------------------------------------------------------------------------- /lib/core/facets/filetest/root.rb: -------------------------------------------------------------------------------- 1 | module FileTest 2 | 3 | module_function 4 | 5 | # Is the specified directory the root directory? 6 | # 7 | # CREDIT: Jeffrey Schwab 8 | 9 | def root?(dir=nil) 10 | pth = File.expand_path(dir||Dir.pwd) 11 | return true if pth == '/' 12 | return true if pth =~ /^(\w:)?\/$/ 13 | false 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /lib/core/facets/hash/op_mul.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # Like merge operator '+' but merges in reverse order. 4 | # 5 | # h1 = {:a=>1} 6 | # h2 = {:a=>2, :b=>3} 7 | # 8 | # (h1 + h2) #=> { :a=>2, :b=>3 } 9 | # (h1 * h2) #=> { :a=>1, :b=>3 } 10 | # 11 | # CREDIT: Trans 12 | 13 | def *(other) 14 | other.merge(self) 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /lib/core/facets/kernel/not_nil.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | 3 | # The opposite of #nil?. 4 | # 5 | # "hello".not_nil? # -> true 6 | # nil.not_nil? # -> false 7 | # 8 | # CREDIT: Gavin Sinclair 9 | 10 | def not_nil? 11 | ! nil? 12 | end 13 | 14 | # DEPRECATED: #not_nil? it enough. 15 | #alias_method :non_nil?, :not_nil? 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /lib/core/facets/regexp/op_add.rb: -------------------------------------------------------------------------------- 1 | class Regexp 2 | 3 | # Add regular expressions. 4 | # 5 | # /a/ + /b/ == /(?-mix:a)(?-mix:b)/ 6 | # 7 | # Functionally equivalent to: 8 | # 9 | # /ab/ 10 | # 11 | # CREDIT: Tyler Rick 12 | def +(other) 13 | other = Regexp.escape(other) if other.is_a?(String) 14 | /#{self}#{other}/ 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /lib/core/facets/regexp/op_or.rb: -------------------------------------------------------------------------------- 1 | class Regexp 2 | 3 | # Operator form of `Regexp.union`. 4 | # 5 | # /a/ | /b/ #=> /(?-mix:a)|(?-mix:b)/ 6 | # 7 | # If +other+ is not a Regexp it is passed to Regexp.escape. 8 | # 9 | def |(other) 10 | other = Regexp.escape(other) unless Regexp === other 11 | Regexp.union(self, other) 12 | end 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /test/core/enumerable/test_mash.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/enumerable/mash' 2 | 3 | test_case Enumerable do 4 | 5 | method :mash do 6 | 7 | test "is an alias for #graph" do 8 | a = { :a => 1, :b => 2, :c => 3 } 9 | e = { :a => 2, :b => 3, :c => 4 } 10 | r = a.mash{ |k,v| {k => v+1} } 11 | r.assert == e 12 | end 13 | 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/core/string/test_crypt.rb: -------------------------------------------------------------------------------- 1 | covers 'facets/string/crypt' 2 | 3 | test_case String do 4 | 5 | method :crypt do 6 | test do 7 | "abc".crypt('ZZ').assert.start_with?('ZZ') 8 | end 9 | 10 | test do 11 | encrypted = "abc".crypt 12 | salt = encrypted[0..1] 13 | "abc".crypt(salt).assert == encrypted 14 | end 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/standard/math/test_cot.rb: -------------------------------------------------------------------------------- 1 | require 'facets/math/cot' 2 | require 'facets/numeric/range' # used to test within a precision 3 | 4 | test_case Math do 5 | 6 | class_method :cot do 7 | test do 8 | Math.cot(1.0).range(1.0e-6).assert === 1.0 / Math.tan(1.0) 9 | Math.cot(2.0).range(1.0e-6).assert === 1.0 / Math.tan(2.0) 10 | end 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /demo/core/array/missing.md: -------------------------------------------------------------------------------- 1 | ## Array#missing 2 | 3 | require 'facets/array/missing' 4 | 5 | Determine the 'holes' in the values of an array. Returns the missing elements 6 | in an array set. 7 | 8 | [1,3..3].missing.assert == [2] 9 | [1..5,10..12].missing.assert == [6..9] 10 | [100, 9..11, 14, 1..5, 16, 10..12, 17..17].missing.assert == [6..8, 13, 15, 18..99] 11 | -------------------------------------------------------------------------------- /demo/core/array/split.md: -------------------------------------------------------------------------------- 1 | ## Array#split 2 | 3 | require 'facets/array/split' 4 | 5 | Split on matching pattern. Unlike #divide, this does not include matching 6 | elements. 7 | 8 | ['a','b','c'].split('b').assert == [['a'],['c']] 9 | 10 | a = ['a1','a2','b1','a3','b2','a4'] 11 | a.split(/^b/).assert == [['a1','a2'],['a3'],['a4']] 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib/core/facets/hash/insert.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | 3 | # As with #store but only if the key isn't 4 | # already in the hash. 5 | # 6 | # TODO: Would #store? be a better name? 7 | # 8 | # CREDIT: Trans 9 | 10 | def insert(name, value) 11 | if key?(name) 12 | false 13 | else 14 | store(name,value) 15 | true 16 | end 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /lib/core/facets/string/number.rb: -------------------------------------------------------------------------------- 1 | class String 2 | 3 | # Returns true if it's a decimal digits. 4 | # 5 | # "123_456_789_123_456_789.123_456_000_111".number? # => true 6 | # "1.23".number? # => true 7 | # "1.23a".number? # => false 8 | # 9 | # CREDIT: u2 10 | 11 | def number? 12 | !!self.match(/\A[+-]?\d+?(_?\d+?)*?(\.\d+(_?\d+?)*?)?\Z/) 13 | end 14 | end -------------------------------------------------------------------------------- /lib/standard/facets/math/linsolve.rb: -------------------------------------------------------------------------------- 1 | module Math 2 | 3 | # Returns real solution(s) of+a+x + +b+ = +c+ or +nil+
4 | # if no or an infinite number of solutions exist. If
5 | # c is missing it is assumed to be 0.
6 | #
7 | # @author Josef Schugt
8 | def self.linsolve(a, b, c = 0.0)
9 | a == 0 ? nil : (c - b) / a
10 | end
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/lib/standard/facets/pathname/null.rb:
--------------------------------------------------------------------------------
1 | class Pathname
2 |
3 | # Platform dependent null device.
4 | #
5 | # CREDIT: Daniel Burger
6 |
7 | def self.null
8 | case RUBY_PLATFORM
9 | when /mswin/i
10 | 'NUL'
11 | when /amiga/i
12 | 'NIL:'
13 | when /openvms/i
14 | 'NL:'
15 | else
16 | '/dev/null'
17 | end
18 | end
19 |
20 | end
21 |
--------------------------------------------------------------------------------
/test/core/file/test_read_list.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/file/read_list'
2 |
3 | test_case File do
4 |
5 | class_method :read_list do
6 |
7 | test_file = 'tmp/read_list.txt'
8 |
9 | test do
10 | File.open(test_file, 'w'){ |f| f << "line 1\nline 2\n#line 3" }
11 | File.read_list(test_file).assert == ['line 1', 'line 2']
12 | end
13 |
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/test/core/hash/test_insert.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/hash/insert'
2 |
3 | test_case Hash do
4 |
5 | method :insert do
6 |
7 | test do
8 | h = {:a=>1, :b=>2}
9 |
10 | h.assert.insert(:c,3)
11 | h.assert == {:a=>1, :b=>2, :c=>3}
12 |
13 | h.refute.insert(:a,0)
14 | h.assert == {:a=>1, :b=>2, :c=>3}
15 | end
16 |
17 | end
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/test/core/hash/test_to_proc.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/hash/to_proc'
2 |
3 | test_case Hash do
4 |
5 | method :to_proc do
6 |
7 | test do
8 | c = Class.new do
9 | attr_accessor :a
10 | end
11 |
12 | h = {:a => 1}
13 | o = c.new
14 |
15 | h.to_proc.call(o)
16 |
17 | o.a.assert == 1
18 | end
19 |
20 | end
21 |
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/test/core/module/test_remove.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/module/remove'
2 |
3 | test_case Module do
4 |
5 | method :remove do
6 |
7 | test do
8 | c = Class.new do
9 | def the_removed_method ; 'not here' ; end
10 | remove :the_removed_method
11 | end
12 |
13 | c.new.refute.respond_to?(:the_removed_method)
14 | end
15 |
16 | end
17 |
18 | end
19 |
--------------------------------------------------------------------------------
/test/core/string/test_mscan.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/mscan'
2 |
3 | test_case String do
4 |
5 | method :mscan do
6 |
7 | test do
8 | r = 'abc,def,gh'.mscan(/[,]/)
9 | assert( r.all?{ |md| MatchData === md } )
10 | r.to_a.length.assert == 2
11 | r[0][0].assert == ','
12 | r[1][0].assert == ','
13 | end
14 |
15 | end
16 |
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/test/core/string/test_nchar.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/nchar'
2 |
3 | test_case String do
4 |
5 | method :nchar do
6 |
7 | test do
8 | "abcxyz".nchar(3).assert == "abc"
9 | "abcxyz".nchar(-3).assert == "xyz"
10 | "abcxyz".nchar(3, 'HI').assert == "HIxyz"
11 | "abcxyz".nchar(-3, 'HI').assert == "abcHI"
12 | end
13 |
14 | end
15 |
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/demo/core/array/delete_unless.md:
--------------------------------------------------------------------------------
1 | ## Array#delete_unless
2 |
3 | require 'facets/array/delete_unless'
4 |
5 | The method `#delete_unless` is the inverse of `#delete_if`.
6 |
7 | a = [1,2,3]
8 | a.delete_unless{ |e| e == 2 }
9 | a.assert == [2]
10 |
11 | [1,2,3].delete_unless{ |x| x < 2 }.assert == [1]
12 | [1,2,3].delete_unless(&:even?).assert == [2]
13 |
14 |
--------------------------------------------------------------------------------
/demo/core/array/nonuniq.md:
--------------------------------------------------------------------------------
1 | ## Array#nonuniq
2 |
3 | require 'facets/array/nonuniq'
4 |
5 | Returns a list of non uniq elements.
6 |
7 | a = [1, 1, 2, 2, 3, 4, 5]
8 | a.nonuniq.sort.assert == [1, 2]
9 |
10 | ## Array#nonuniq!
11 |
12 | Same as #nonuniq but acts in place.
13 |
14 | a = [1, 1, 2, 2, 3, 4, 5]
15 | a.nonuniq!
16 | a.sort.assert == [1,2]
17 |
--------------------------------------------------------------------------------
/demo/core/array/occurrence.md:
--------------------------------------------------------------------------------
1 | ## Array#occurrence
2 |
3 | require 'facets/array/occurrence'
4 |
5 | Create a hash of each uniq element of the array
6 | and how many time each appears.
7 |
8 | r = [:a,:a,:b,:c,:c,:c].occurrence
9 | r.assert == { :a => 2, :b => 1, :c => 3 }
10 |
11 | r = [2,2,3,4,4,4].occurrence{|i| i % 2}
12 | r.assert == { 0 => 5, 1 => 1 }
13 |
14 |
--------------------------------------------------------------------------------
/demo/core/array/split_at.md:
--------------------------------------------------------------------------------
1 | ## Array#split_at
2 |
3 | require 'facets/array/split_at'
4 |
5 | Split on the first element that matches using Array#index.
6 |
7 | ['a','b','c'].split_at('b').assert == [['a'],'b',['c']]
8 |
9 | a = ['a1','a2','b12','a3','b2','a4']
10 | a.split_at{|e| e.size == 3}.assert == [['a1','a2'],'b12',['a3','b2','a4']]
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lib/core/facets/file/read_binary.rb:
--------------------------------------------------------------------------------
1 | class File
2 |
3 | # Read in a file as binary data.
4 | #
5 | # Assuming we had a binary file 'binary.dat'.
6 | #
7 | # File.read_binary('binary.dat')
8 | #
9 | # CREDIT: George Moschovitis
10 |
11 | def self.read_binary(fname)
12 | open(fname, 'rb') do |f|
13 | return f.read
14 | end
15 | end
16 |
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/lib/core/facets/module/to_obj.rb:
--------------------------------------------------------------------------------
1 | class Module
2 |
3 | # Create an instance of Object and extend it with +self+.
4 | #
5 | # mod = Module.new do
6 | # def foo; "foo"; end
7 | # end
8 | #
9 | # obj = mod.to_obj
10 | #
11 | # obj.foo #=> "foo"
12 | #
13 | def to_obj
14 | o = Object.new
15 | o.extend self
16 | o
17 | end
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/test/core/array/test_poke.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/pull'
2 |
3 | test_case Array do
4 |
5 | method :poke do
6 |
7 | test do
8 | a = [1,2,3]
9 | a.poke(9)
10 | a.assert == [9,1,2,3]
11 | end
12 |
13 | test do
14 | a = [2,3]
15 | a.poke(1).assert == [1,2,3]
16 | a.poke(4).assert == [4,1,2,3]
17 | end
18 |
19 | end
20 |
21 | end
22 |
--------------------------------------------------------------------------------
/test/standard/math/test_coth.rb:
--------------------------------------------------------------------------------
1 | require 'facets/math/coth'
2 | require 'facets/numeric/range' # used to test within a precision
3 |
4 | test_case Math do
5 |
6 | class_method :coth do
7 | test do
8 | Math.coth(1.0).range(1.0e-6).assert === 1.0 / Math.tanh(1.0)
9 | Math.coth(2.0).range(1.0e-6).assert === 1.0 / Math.tanh(2.0)
10 | end
11 | end
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/test/standard/math/test_median.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/math/median'
2 |
3 | test_case Math do
4 |
5 | class_method :median do
6 | test "fractional" do
7 | r = Math.median [1, 2, 3, 3, 6, 11, 20, 20]
8 | r.assert == 4.5
9 | end
10 |
11 | test "whole value" do
12 | r = Math.median [1, 2, 4, 6, 8]
13 | r.assert == 4
14 | end
15 | end
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/demo/core/array/ideal_entropy.md:
--------------------------------------------------------------------------------
1 | ## Array#ideal_entropy
2 |
3 | require 'facets/array/entropy'
4 |
5 | Returns the maximum possible Shannon entropy of the array
6 | with given size assuming that it is an "order-0" source
7 | (each element is selected independently of the next).
8 |
9 | %w{ a b }.ideal_entropy.assert == 1.0
10 | %w{ a a b b }.ideal_entropy.assert == 2.0
11 |
12 |
--------------------------------------------------------------------------------
/lib/core/facets/class/singleton_class.rb:
--------------------------------------------------------------------------------
1 | class Class
2 |
3 | # Return true if a class is the singleton class of
4 | # an object.
5 | #
6 | # @uncommon
7 | # require 'facets/class/singleton_class'
8 | #
9 | def singleton_class?
10 | ! ancestors.include?( self ) rescue false
11 | end
12 |
13 | # @deprecated
14 | alias :singleton? :singleton_class?
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/lib/core/facets/dir/parent.rb:
--------------------------------------------------------------------------------
1 | class Dir
2 |
3 | # Is a path parental to another?
4 | #
5 | # Dir.parent?('parent', 'parent/child') #=> true
6 | #
7 | # TODO: Needs improvement.
8 | #
9 | # TODO: Instance version?
10 |
11 | def self.parent?(parent_path, child_path)
12 | %r|^#{Regexp.escape(parent_path)}| =~ child_path ? true : false
13 | end
14 |
15 | end
16 |
17 |
--------------------------------------------------------------------------------
/lib/core/facets/integer/multiple.rb:
--------------------------------------------------------------------------------
1 | class Integer
2 |
3 | # Is +self+ a multiple of a given number?
4 | #
5 | # 7.multiple?(2) #=> false
6 | # 8.multiple?(2) #=> true
7 | #
8 | # CREDIT: Trans
9 |
10 | def multiple?(number)
11 | if number.zero?
12 | zero? ? true : false
13 | else
14 | self % number == 0
15 | end
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/lib/core/facets/load_path/search.rb:
--------------------------------------------------------------------------------
1 | class << $LOAD_PATH
2 |
3 | # Search load path for matching patterns.
4 | #
5 | def search(match)
6 | found = []
7 | uniq.map do |path|
8 | list = Dir.glob(File.join(File.expand_path(path), match))
9 | list = list.map{ |d| d.chomp('/') }
10 | found.concat(list)
11 | end
12 | found
13 | end
14 |
15 | end
16 |
17 |
--------------------------------------------------------------------------------
/lib/core/facets/range.rb:
--------------------------------------------------------------------------------
1 | require_relative 'range/combine.rb'
2 | require_relative 'range/overlap.rb'
3 | #require_relative 'range/quantile.rb' # uncommon
4 | #require_relative 'range/op_add.rb' # too new
5 | #require_relative 'range/op_sub.rb' # too new
6 | require_relative 'range/to_rng.rb'
7 | require_relative 'range/umbrella.rb'
8 | require_relative 'range/within.rb'
9 |
10 |
--------------------------------------------------------------------------------
/lib/standard/facets/math/sum.rb:
--------------------------------------------------------------------------------
1 | module Math
2 |
3 | # Returns sum. When a block is given, summation is taken over the
4 | # each result of block evaluation.
5 | #
6 | def self.sum(array) #:yield:
7 | sum = 0.0
8 | if block_given?
9 | array.each{|i| sum += yield(i)}
10 | else
11 | array.each{|i| sum += i}
12 | end
13 | sum
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/test/core/array/test_splice.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/splice'
2 |
3 | test_case Array do
4 |
5 | method :splice do
6 |
7 | test do
8 | a = [1,2,3]
9 | a.splice(1).assert == 2
10 | a.assert == [1,3]
11 | end
12 |
13 | test do
14 | a = [1,2,3]
15 | a.splice(1,4).assert == 4
16 | a.assert == [1,4,3]
17 | end
18 |
19 | end
20 |
21 | end
22 |
--------------------------------------------------------------------------------
/test/core/module/test_nodef.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/module/nodef'
2 |
3 | test_case Module do
4 |
5 | method :nodef do
6 |
7 | test do
8 | c = Class.new do
9 | def the_undefined_method ; 'not here' ; end
10 | nodef :the_undefined_method
11 | end
12 |
13 | c.new.refute.respond_to?(:the_undefined_method)
14 | end
15 |
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/test/core/regexp/test_to_re.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/regexp/to_re'
2 |
3 | test_case Regexp do
4 |
5 | method :to_re do
6 |
7 | test do
8 | r = /0..10/
9 | r.to_re.assert == r.to_re
10 | end
11 |
12 | end
13 |
14 | method :to_regexp do
15 |
16 | test do
17 | r = /0..10/
18 | r.to_regexp.assert == r
19 | end
20 |
21 | end
22 |
23 | end
24 |
25 |
--------------------------------------------------------------------------------
/test/core/string/test_edit_distance.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/edit_distance'
2 |
3 | test_case String do
4 |
5 | method :edit_distance do
6 |
7 | test do
8 | d = "pretzel".edit_distance('pretzil')
9 | d.assert = 1
10 | end
11 |
12 | test do
13 | d = "zretzel".edit_distance('pretzil')
14 | d.assert = 2
15 | end
16 |
17 | end
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/work/bench/general/bench_methods.rb:
--------------------------------------------------------------------------------
1 |
2 | class ManyMethods
3 |
4 | puts "Generating methods..."
5 |
6 | (0..100000).each do |i|
7 | define_method( "_#{i}" ) { puts "Called method #{i}." }
8 | end
9 |
10 | end
11 |
12 | mm = ManyMethods.new
13 |
14 | n1 = Time.now
15 | mm._50000
16 | n2 = Time.now
17 | puts "Time to call a single method among 100000: #{(n2 - n1).to_f} seconds."
18 |
--------------------------------------------------------------------------------
/lib/core/facets/kernel/deep_copy.rb:
--------------------------------------------------------------------------------
1 | module Kernel
2 |
3 | # Anything that can be marshaled can be copied in totality.
4 | #
5 | # "ABC".deep_copy #=> "ABC"
6 | #
7 | # NOTE: Not sure why we wouldn't just call this #copy, but
8 | # the term +deep_copy+ seems to be the common practive.
9 | def deep_copy
10 | Marshal::load(Marshal::dump(self))
11 | end
12 |
13 | end
14 |
15 |
--------------------------------------------------------------------------------
/lib/standard/facets/pathname/readline.rb:
--------------------------------------------------------------------------------
1 | class Pathname
2 | # Reads the first line of the file
3 | #
4 | # Captures the best practice from this post at stack overflow:
5 | # https://stackoverflow.com/questions/1490138/reading-the-first-line-of-a-file-in-ruby
6 | #
7 | # Credit: Ryan Duryea
8 | def readline(*args)
9 | open { |f| f.readline(*args) }
10 | end
11 | end
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/core/array/test_store.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/store'
2 |
3 | test_case Array do
4 |
5 | method :store do
6 |
7 | test do
8 | a = [1,2,3,4,5]
9 | a.store(0, :A)
10 | a.assert == [:A,2,3,4,5]
11 | end
12 |
13 | test do
14 | a = [1,2,3,4,5]
15 | a.store(-1, :Z)
16 | a.assert == [1,2,3,4,:Z]
17 | end
18 |
19 | end
20 |
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/test/core/string/test_cmp.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/cmp'
2 |
3 | test_case String do
4 |
5 | method :cmp do
6 |
7 | test 'on strings' do
8 | "abc".cmp("abc").assert == 0
9 | "abc".cmp("abcd").assert == -1
10 | "abcd".cmp("abc").assert == 1
11 | "abc".cmp("bcd").assert == -1
12 | "bcd".cmp("abc").assert == 1
13 | end
14 |
15 | end
16 |
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/test/core/string/test_uppercase.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/uppercase'
2 |
3 | test_case String do
4 |
5 | method :uppercase do
6 |
7 | test do
8 | "bob".uppercase.assert == "Bob"
9 | end
10 |
11 | test do
12 | "boB".uppercase.assert == "BoB"
13 | end
14 |
15 | test do
16 | "BoB".uppercase.assert == "BoB"
17 | end
18 |
19 | end
20 |
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/work/consider/core/module/subfield_accessors.rb:
--------------------------------------------------------------------------------
1 | class Module
2 |
3 | def subfield_accessors(field, subfields)
4 | subfields.each do |subfield, index|
5 | define_method(subfield) do
6 | self.send(field)[index]
7 | end
8 |
9 | define_method("#{subfield}=") do |value|
10 | self.send(field)[index] = value
11 | end
12 | end
13 | end
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/work/trash/site/js/hover.js:
--------------------------------------------------------------------------------
1 |
2 | function hover(thisElem, imgName) {
3 | ro = document.getElementById('hover');
4 | ro.posX = thisElem.posX;
5 | ro.posY = thisElem.posY;
6 | alert(thisElem.posX);
7 | roi = document.getElementById('hover_img');
8 | roi.src = imgName;
9 | }
10 |
11 | function unhover() {
12 | ro = document.getElementById('hover');
13 | ro.style.left = "-200px"
14 | }
15 |
--------------------------------------------------------------------------------
/lib/core/facets/class/pathize.rb:
--------------------------------------------------------------------------------
1 | require 'facets/string/pathize'
2 |
3 | class Class
4 |
5 | # Converts a class name to a unix path.
6 | #
7 | # module ::Example
8 | # class PathizeExample
9 | # end
10 | # end
11 | #
12 | # Example::PathizeExample.pathize #=> "example/pathize_example"
13 | #
14 | def pathize
15 | name.pathize
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/lib/core/facets/module/can.rb:
--------------------------------------------------------------------------------
1 | class Module
2 |
3 | # An alias for #extend.
4 | #
5 | # module EgCan
6 | # def foo; "foo"; end
7 | # end
8 | #
9 | # class EgCanClass
10 | # can EgCan
11 | # end
12 | #
13 | # EgCanClass.foo #=> 'foo'
14 | #
15 | # BTW, why is Forwardable an -able? It's not a mixin!
16 |
17 | alias_method :can, :extend
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/lib/core/facets/version.rb:
--------------------------------------------------------------------------------
1 | module Facets
2 | #
3 | def self.index
4 | @index ||= (
5 | require 'yaml'
6 | YAML.load(File.new(File.dirname(__FILE__) + '/facets.yml'))
7 | )
8 | end
9 |
10 | #
11 | def self.const_missing(name)
12 | key = name.to_s.downcase
13 | index[key] || super(name)
14 | end
15 |
16 | # deprecate
17 | VERSION = '3.0.0'
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/test/core/array/test_delete_unless.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/delete_unless'
2 |
3 | test_case Array do
4 |
5 | method :delete_unless do
6 |
7 | test 'with an explicit block' do
8 | [1,2,3].delete_unless{ |x| x < 2 }.assert == [1]
9 | end
10 |
11 | test 'with an implicit block' do
12 | [1,2,3].delete_unless(&:even?).assert == [2]
13 | end
14 |
15 | end
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/demo/core/string/exclude.md:
--------------------------------------------------------------------------------
1 | ## String#exclude?
2 |
3 | require 'facets/string/exclude'
4 |
5 | The inverse of include?.
6 |
7 | "aaaa".assert.exclude?('bb')
8 | "aaab".assert.exclude?('bb')
9 | "aaba".assert.exclude?('bb')
10 | "baaa".assert.exclude?('bb')
11 |
12 | "abba".refute.exclude?('bb')
13 | "aabb".refute.exclude?('bb')
14 | "bbaa".refute.exclude?('bb')
15 |
16 |
--------------------------------------------------------------------------------
/lib/core/facets/class.rb:
--------------------------------------------------------------------------------
1 | require_relative 'class/descendants.rb'
2 | #require_relative 'class/hierarchically' # uncommon
3 | require_relative 'class/methodize.rb'
4 | require_relative 'class/pathize.rb'
5 | #require_relative 'class/preallocate.rb' # uncommon
6 | #require_relative 'class/singleton.rb' # uncommon
7 | require_relative 'class/subclasses.rb'
8 | require_relative 'class/to_proc.rb'
9 |
10 |
--------------------------------------------------------------------------------
/lib/core/facets/hash/delete_unless.rb:
--------------------------------------------------------------------------------
1 | class Hash
2 |
3 | # Inverse of #delete_if.
4 | #
5 | # h = { :a => 1, :b => 2, :c => 3 }
6 | # r = h.delete_unless{|k,v| v == 1}
7 | # r #=> { :a => 1 }
8 | # h #=> { :a => 1 }
9 | #
10 | # CREDIT: Daniel Schierbeck
11 |
12 | def delete_unless #:yield:
13 | delete_if{ |key, value| ! yield(key, value) }
14 | end
15 |
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/demo/core/array/splice.md:
--------------------------------------------------------------------------------
1 | ## Array#splice
2 |
3 | require 'facets/array/splice'
4 |
5 | Splice acts as a combination of #slice! and #store. If one argument is given it
6 | calls #slice!, if two are given it calls #store.
7 |
8 | a = [1,2,3]
9 | a.splice(1).assert == 2
10 | a.assert == [1,3]
11 |
12 | b = [1,2,3]
13 | b.splice(1,4).assert == 4
14 | b.assert == [1,4,3]
15 |
--------------------------------------------------------------------------------
/demo/core/string/pathize.md:
--------------------------------------------------------------------------------
1 | ## String#pathize
2 |
3 | require 'facets/string/pathize'
4 |
5 | module name
6 |
7 | a = "Foo::Base"
8 | x = "foo/base"
9 | a.pathize.assert == x
10 |
11 | path name
12 |
13 | a = "foo/base"
14 | x = "foo/base"
15 | a.pathize.assert == x
16 |
17 | name space
18 |
19 | a = "foo__base"
20 | x = "foo/base"
21 | a.pathize.assert == x
22 |
23 |
--------------------------------------------------------------------------------
/lib/core/facets/array/merge.rb:
--------------------------------------------------------------------------------
1 | class Array
2 |
3 | # In place #merge.
4 | #
5 | # a = [1,2]
6 | # a.merge! [2,3]
7 | # a #=> [1,2,3]
8 | #
9 | # CREDIT: Trans
10 |
11 | def merge!( other )
12 | self.replace(self.merge(other))
13 | end
14 |
15 | # Alias for |.
16 | #
17 | # [1,2].merge([2,3]) #=> [1,2,3]
18 | #
19 | alias_method :merge, :|
20 |
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/lib/core/facets/integer/of.rb:
--------------------------------------------------------------------------------
1 | class Integer
2 |
3 | # Like #times but returns a collection of the yield results.
4 | #
5 | # a = 3.of { |i| "#{i+1}" }
6 | # a #=> [ "1", "2", "3" ]
7 | #
8 |
9 | def of(&block)
10 | Array.new(self, &block)
11 | end
12 |
13 | # Time warn aliases for #of.
14 | alias_method :times_collect, :of
15 | alias_method :times_map, :of
16 |
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/test/core/array/test_split.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/split'
2 |
3 | test_case Array do
4 |
5 | method :split do
6 |
7 | test do
8 | ['a','b','c'].split('b').assert == [['a'], ['c']]
9 | end
10 |
11 | test "empty" do
12 | [].split('a').assert == []
13 | end
14 |
15 | test "same" do
16 | ['a'].split('a').assert == []
17 | end
18 |
19 | end
20 |
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/test/core/kernel/test_meta_eval.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/kernel/meta_eval'
2 |
3 | test_case Kernel do
4 |
5 | method :meta_eval do
6 |
7 | test do
8 | o = Object.new
9 | o.meta_eval do
10 | @y = "y"
11 | end
12 | o.instance_variable_get("@y").refute == "y"
13 | (class << o; self; end).instance_variable_get("@y").assert == "y"
14 | end
15 |
16 | end
17 |
18 | end
19 |
--------------------------------------------------------------------------------
/work/consider/core/module/bool_accessor.rb:
--------------------------------------------------------------------------------
1 | class Module
2 |
3 | def bool_accessor(*attrs)
4 | attrs.each do |attr|
5 | attr_writer(attr)
6 | bool_reader(attr)
7 | end
8 | end
9 |
10 | def bool_reader(*attrs)
11 | attrs.each do |attr|
12 | attr_reader attr
13 | define_method("#{attr}?") do
14 | !!send(attr)
15 | end
16 | end
17 | end
18 |
19 | end
20 |
--------------------------------------------------------------------------------
/demo/core/string/natcmp.md:
--------------------------------------------------------------------------------
1 | ## String#natcmp
2 |
3 | require 'facets/string/natcmp'
4 |
5 | "my_prog_v1.1.0".natcmp( "my_prog_v1.2.0").assert == -1
6 | "my_prog_v1.2.0".natcmp("my_prog_v1.10.0").assert == -1
7 | "my_prog_v1.2.0".natcmp( "my_prog_v1.1.0").assert == 1
8 | "my_prog_v1.10.0".natcmp("my_prog_v1.2.0").assert == 1
9 | "my_prog_v1.0.0".natcmp( "my_prog_v1.0.0").assert == 0
10 |
11 |
--------------------------------------------------------------------------------
/lib/standard/facets/math/lcm.rb:
--------------------------------------------------------------------------------
1 | module Math
2 |
3 | # Least common multiple of +m+ and +n+, computed by multiplying
4 | # +m+ and +n+ and dividing the product by the gcd of +m+ and +n+,
5 | # +nil+ for non-positive numbers.
6 | def self.lcm(m, n)
7 | m = Integer(m)
8 | n = Integer(n)
9 | if m <= 0 || n <= 0
10 | return nil
11 | end
12 | m / gcd(m, n) * n
13 | end
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/test/core/class/test_subclasses.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/class/subclasses'
2 |
3 | test_case Class do
4 |
5 | method :subclasses do
6 |
7 | # class with a number of subclasses
8 | c = Class.new
9 | x = Class.new(c)
10 | y = Class.new(c)
11 | z = Class.new(c)
12 | zz = Class.new(z)
13 |
14 | test do
15 | c.subclasses == [x, y, z]
16 | end
17 |
18 | end
19 |
20 | end
21 |
22 |
--------------------------------------------------------------------------------
/test/core/hash/test_weave.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/hash/weave'
2 |
3 | test_case Hash do
4 |
5 | method :weave do
6 |
7 | test do
8 | b = { :a=>1, :b=>[1,2,3], :c=>{ :x=>'X' } }
9 | c = { :a=>2, :b=>[4,5,6], :c=>{ :x=>'A', :y => 'B' } }
10 | x = { :a=>2, :b=>[1,2,3,4,5,6], :c=>{ :x => 'A', :y => 'B' } }
11 | b.weave(c).assert == x
12 | end
13 |
14 | end
15 |
16 | end
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/core/kernel/test_instance_assign.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/kernel/instance_assign'
2 |
3 | test_case Kernel do
4 |
5 | method :instance_assign do
6 |
7 | test do
8 | ahash = { "z"=>0, "@a"=>1, "@b"=>2 } #, "@@a"=>3 }
9 | instance_assign(ahash)
10 | @z.assert == 0
11 | @a.assert == 1
12 | @b.assert == 2
13 | #@@a.assert == 3
14 | end
15 |
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/test/core/kernel/test_not_nil.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/kernel/not_nil'
2 |
3 | test_case Kernel do
4 |
5 | method :not_nil? do
6 |
7 | test do
8 | 5.assert.not_nil?
9 | end
10 |
11 | test do
12 | :x.assert.not_nil?
13 | end
14 |
15 | test do
16 | false.assert.not_nil?
17 | end
18 |
19 | test do
20 | nil.refute.not_nil?
21 | end
22 |
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/test/standard/math/test_exp2.rb:
--------------------------------------------------------------------------------
1 | require 'facets/math/exp2'
2 | require 'facets/numeric/range' # used to test within a precision
3 |
4 | test_case Math do
5 |
6 | class_method :exp2 do
7 | test do
8 | Math.exp2(0.0).range(1.0e-6).assert === 1.0
9 | Math.exp2(0.5).range(1.0e-6).assert === Math.sqrt(2.0)
10 | Math.exp2(1.0).range(1.0e-6).assert === 2.0
11 | end
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/work/trash/site-jekyll/assets/scripts/hover.js:
--------------------------------------------------------------------------------
1 |
2 | function hover(thisElem, imgName) {
3 | ro = document.getElementById('hover');
4 | ro.posX = thisElem.posX;
5 | ro.posY = thisElem.posY;
6 | alert(thisElem.posX);
7 | roi = document.getElementById('hover_img');
8 | roi.src = imgName;
9 | }
10 |
11 | function unhover() {
12 | ro = document.getElementById('hover');
13 | ro.style.left = "-200px"
14 | }
15 |
--------------------------------------------------------------------------------
/demo/core/string/modulize.md:
--------------------------------------------------------------------------------
1 | ## String#modulize
2 |
3 | require 'facets/string/modulize'
4 |
5 | snakecase
6 |
7 | a = "foo_bar"
8 | r = "FooBar"
9 | a.modulize.assert == r
10 |
11 | path name
12 |
13 | a = "foo/bar"
14 | r = "Foo::Bar"
15 | a.modulize.assert == r
16 |
17 | on methodized string
18 |
19 | a = "foo__bar"
20 | r = "Foo::Bar"
21 | a.modulize.assert == r
22 |
23 |
--------------------------------------------------------------------------------
/lib/core/facets/hash/diff.rb:
--------------------------------------------------------------------------------
1 | class Hash
2 |
3 | # Difference comparison of two hashes.
4 | #
5 | # h1 = {:a=>1,:b=>2}
6 | # h2 = {:a=>1,:b=>3}
7 | #
8 | # h1.diff(h2) #=> {:b=>2}
9 | # h2.diff(h1) #=> {:b=>3}
10 | #
11 | def diff(hash)
12 | h1 = self.dup.delete_if{ |k,v| hash[k] == v }
13 | h2 = hash.dup.delete_if{ |k,v| has_key?(k) }
14 | h1.merge(h2)
15 | end
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/lib/core/facets/kernel/with.rb:
--------------------------------------------------------------------------------
1 | module Kernel
2 |
3 | # Like returning but exectues the block
4 | # via instance_eval.
5 | #
6 | # def foo
7 | # with values = [] do
8 | # self << 'bar'
9 | # self << 'baz'
10 | # end
11 | # end
12 | #
13 | # foo # => ['bar', 'baz']
14 | #
15 | def with(obj=self, &block)
16 | obj.instance_eval(&block)
17 | end
18 |
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/test/core/binding/test_op.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/binding/op'
2 |
3 | test_case Binding do
4 |
5 | a = 1
6 | b = 2
7 | x = "hello"
8 |
9 | bind = binding
10 |
11 | method :[] do
12 | test do
13 | bind["x"].assert == "hello"
14 | end
15 | end
16 |
17 | method :[]= do
18 | test do
19 | bind["x"] = "goodbye"
20 | bind["x"].assert == "goodbye"
21 | end
22 | end
23 |
24 | end
25 |
--------------------------------------------------------------------------------
/test/core/kernel/test_object_class.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/kernel/object_class'
2 | covers 'facets/kernel/__class__'
3 |
4 | test_case Kernel do
5 |
6 | method :object_class do
7 |
8 | test do
9 | self.object_class.assert == self.class
10 | end
11 |
12 | end
13 |
14 | method :__class__ do
15 |
16 | test do
17 | self.__class__.assert == self.class
18 | end
19 |
20 | end
21 |
22 | end
23 |
--------------------------------------------------------------------------------
/test/core/module/test_instance_method.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/module/instance_method'
2 |
3 | test_case Module do
4 |
5 | method :instance_method! do
6 |
7 | test do
8 | c = Class.new do
9 | def x; "x"; end
10 | end
11 |
12 | x1 = c.instance_method!(:x)
13 | x2 = c.instance_method!(:x)
14 |
15 | x1.object_id.assert == x2.object_id
16 | end
17 |
18 | end
19 |
20 | end
21 |
--------------------------------------------------------------------------------
/test/core/module/test_pathize.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/module/pathize'
2 |
3 | test_case Module do
4 |
5 | method :pathize do
6 |
7 | test do
8 | Lemon.pathize.assert == 'lemon'
9 | end
10 |
11 | end
12 |
13 | end
14 |
15 | test_case Class do
16 |
17 | method :pathize do
18 |
19 | test do
20 | Lemon::TestCase.pathize.assert == 'lemon/test_case'
21 | end
22 |
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/test/core/struct/test_replace.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/struct/replace'
2 |
3 | test_case Struct do
4 | method :replace do
5 | test do
6 | s = Struct.new(:name, :age)
7 |
8 | o = s.new('bob', 60)
9 | o.name.assert == 'bob'
10 | o.age.assert == 60
11 |
12 | o.replace(:name=>'tom', :age=>40)
13 |
14 | o.name.assert == 'tom'
15 | o.age.assert == 40
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/demo/core/dir/ascend.md:
--------------------------------------------------------------------------------
1 | ## Dir#ascend
2 |
3 | require 'facets/dir/ascend'
4 |
5 | path = 'A/B/C'
6 |
7 | tmp = []
8 |
9 | Dir.ascend(path) do |d|
10 | tmp << d
11 | end
12 |
13 | tmp.assert == %w{A/B/C A/B A}
14 |
15 | Exclude current path.
16 |
17 | tmp = []
18 |
19 | Dir.ascend(path, false) do |d|
20 | tmp << d
21 | end
22 |
23 | tmp.assert == %w{A/B A}
24 |
25 |
--------------------------------------------------------------------------------
/demo/core/string/methodize.md:
--------------------------------------------------------------------------------
1 | ## String#methodize
2 |
3 | require 'facets/string/methodize'
4 |
5 | module name
6 |
7 | a = "FooBase"
8 | r = "foo_base"
9 | a.methodize.assert == r
10 |
11 | path name
12 |
13 | a = "foo/base"
14 | r = "foo__base"
15 | a.methodize.assert == r
16 |
17 | name space
18 |
19 | a = "Foo::Base"
20 | r = "foo__base"
21 | a.methodize.assert == r
22 |
23 |
--------------------------------------------------------------------------------
/demo/core/string/snakecase.md:
--------------------------------------------------------------------------------
1 | ## String#snakecase
2 |
3 | require 'facets/string/snakecase'
4 |
5 | Underscore a string such that camelcase, dashes and spaces are
6 | replaced by underscores. This is the reverse of {#camelcase},
7 | albeit not an exact inverse.
8 |
9 | 'my_name'.snakecase.assert == 'my_name'
10 |
11 | 'MyName'.snakecase.assert == 'my_name'
12 |
13 | 'URI'.snakecase.assert == 'uri'
14 |
15 |
--------------------------------------------------------------------------------
/lib/core/facets/class/methodize.rb:
--------------------------------------------------------------------------------
1 | require 'facets/string/methodize'
2 |
3 | class Class
4 |
5 | # Translate a class name to a suitable method name.
6 | #
7 | # module ::Example
8 | # class MethodizeExample
9 | # end
10 | # end
11 | #
12 | # Example::MethodizeExample.methodize #=> "example__methodize_example"
13 | #
14 | def methodize
15 | name.methodize
16 | end
17 |
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/lib/core/facets/module/memoize.rb:
--------------------------------------------------------------------------------
1 | require 'facets/memoizable'
2 |
3 | class Module
4 |
5 | # This is here for backward compatibility.
6 | #
7 | # @uncommon
8 | # require 'facets/module/memoize'
9 | #
10 | def memoize(*args)
11 | include Memoizable
12 | Memoizable.instance_method(:memoize).bind(self).call(*args)
13 | #super(*args) # TODO: why is super not working here?
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/lib/standard/facets/math/atkinson_index.rb:
--------------------------------------------------------------------------------
1 | require 'facets/math/theil_index'
2 |
3 | module Math
4 |
5 | # Closely related to the Theil index and easily expressible
6 | # in terms of it.
7 | #
8 | # AI = 1-e^{theil_index}
9 | #
10 | # http://en.wikipedia.org/wiki/Atkinson_index
11 | def self.atkinson_index(array)
12 | t = theil_index(array)
13 | (t < 0) ? -1 : 1-Math::E**(-t)
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/test/core/array/test_entropy.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/array/entropy'
2 |
3 | test_case Array do
4 |
5 | method :entropy do
6 |
7 | test do
8 | %w{ a b }.entropy.assert == 1.0
9 | end
10 |
11 | end
12 |
13 | method :ideal_entropy do
14 |
15 | test do
16 | %w{ a b }.ideal_entropy.assert == 1.0
17 | %w{ a a b b }.ideal_entropy.assert == 2.0
18 | end
19 |
20 | end
21 |
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/test/core/dir/test_each_child.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/dir/each_child'
2 |
3 | test_case Dir do
4 |
5 | test_directory = 'test'
6 |
7 | method :each_child do
8 |
9 | test do
10 | c = []
11 | d = Dir.new(test_directory)
12 | d.each_child do |path|
13 | c << path
14 | end
15 | d.close
16 | (['core', 'standard'] - c).assert.empty?
17 | end
18 |
19 | end
20 |
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/test/core/file/test_write.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/file/write'
2 |
3 | test_case File do
4 |
5 | class_method :write do
6 |
7 | test_file = 'tmp/write.txt'
8 |
9 | test do
10 | data = "Test data\n"
11 |
12 | nbytes = File.write(test_file, data)
13 |
14 | out = File.read(test_file)
15 | out.assert == data
16 | out.size.assert == nbytes
17 | end
18 |
19 | end
20 |
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/test/core/string/test_lchomp.rb:
--------------------------------------------------------------------------------
1 | covers 'facets/string/lchomp'
2 |
3 | test_case String do
4 |
5 | method :lchomp do
6 |
7 | test do
8 | s = "xxboo"
9 | r = s.lchomp("xx")
10 | r.assert == "boo"
11 | end
12 |
13 | end
14 |
15 | method :lchomp! do
16 |
17 | test do
18 | s = "xxboo"
19 | s.lchomp!("xx")
20 | s.assert == "boo"
21 | end
22 |
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/test/standard/math/test_exp10.rb:
--------------------------------------------------------------------------------
1 | require 'facets/math/exp10'
2 | require 'facets/numeric/range' # used to test within a precision
3 |
4 | test_case Math do
5 |
6 | class_method :exp10 do
7 | test do
8 | Math.exp10(0.0).range(1.0e-6).assert === 1.0
9 | Math.exp10(0.5).range(1.0e-6).assert === Math.sqrt(10.0)
10 | Math.exp10(1.0).range(1.0e-6).assert === 10.0
11 | end
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/test/standard/math/test_sinc.rb:
--------------------------------------------------------------------------------
1 | require 'facets/math/sinc'
2 |
3 | test_case Math do
4 |
5 | class_method :sinc do
6 | test do
7 | Math.sinc( 0.0).assert == 1.0
8 | Math.sinc( 1.0).assert == Math.sin(1.0)
9 | Math.sinc(-1.0).assert == Math.sin(1.0)
10 | Math.sinc( 2.0).assert == 0.5 * Math.sin(2.0)
11 | Math.sinc(-2.0).assert == 0.5 * Math.sin(2.0)
12 | end
13 | end
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/work/sandbox/safe-study/safe_extension.rb:
--------------------------------------------------------------------------------
1 | require 'facets/module/module_require'
2 |
3 | module StringExtensions
4 | end
5 |
6 | printer = "hello world"
7 |
8 | StringExtensions::String = class << printer; self; end
9 |
10 | module StringExtensions
11 | module_require '~/ruby/facets/trunk/lib/core/ext/facets/string/titlecase.rb'
12 | end
13 |
14 | #printer.extend StringExtensions
15 |
16 | puts printer.titlecase
17 |
18 |
--------------------------------------------------------------------------------
/demo/core/array/collapse.md:
--------------------------------------------------------------------------------
1 | ## Array#collapse
2 |
3 | require 'facets/array/collapse'
4 |
5 | Simplify an array by flattening it then compacting it.
6 |
7 | [1,[2,nil,[3]],nil,4].collapse.assert == [1,2,3,4]
8 |
9 | ## Array#collapse!
10 |
11 | Simplify an array by flattening it in place then compacting it in place.
12 |
13 | a = [1, nil, [1, 2], nil, [[3]]]
14 | a.collapse!
15 | a.assert == [1, 1, 2, 3]
16 |
--------------------------------------------------------------------------------