--------------030403050609000409050206
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
... for lazy typers - can also be used for obfuscation. Might make your
code unmaintainable, instable or both.
Use at own risk.
robert
--------------030403050609000409050206
Content-Type: text/plain;
name illy-1.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename illy-1.rb"
module Kernel
alias _method_missing method_missing
def method_missing(s,*a,&b)
candidates ethod_candidates(s)
case candidates.size
when 0
_method_missing(s,*a,&b)
when 1
send(candidates[0],*a,&b)
else
raise NameError,
"Ambiguous name: #{s}, "\
"candidates: #{candidates.join ', '}"
end
end
private
# find names of which sym is prefix
def method_candidates(sym)
methods.grep(/\A#{sym}/i)
end
end
p %w{foo bar}.inj(0) {|le, s| le + s.length}
module Kernel
# get rid of aeiou and special chars
def method_candidates(sym)
methods.select {|me| /\A#{sym.to_s.gsub(/[aeiou_]/, '')}/i me.gsub(/[aeiou_]/, '')}
end
end
p %w{foo bar}.injct(0) {|le, s| le + s.length}
p %w{foo bar}.inj(0) {|le, s| le + s.length}
p %w{foo bar}.in(0) {|le, s| le + s.length}
--------------030403050609000409050206--