Trans
10/31/2007 3:21:00 PM
On Oct 31, 9:56 am, "David A. Black" <dbl...@rubypal.com> wrote:
> Hi --
>
> On Wed, 31 Oct 2007, kylichuku wrote:
> > Hi there!
>
> > I need to create a method with name, that contains '-' character. Is
> > it possible, and if the answer is "yes", how can I do it?
>
> The only way I know of is:
>
> irb(main):002:0> class C
> irb(main):003:1> define_method("x-y") { puts "Weird method" }
> irb(main):004:1> end
>
> At which point, the only way to call it is:
>
> irb(main):005:0> C.new.send("x-y") # Weird method
>
> In other words, it's not worth the trouble and you should find some
> other solution.
Reminds we, I've thought this notation might be interesting in place
of send:
foo."a-b"
But I think it "scares" poeople. But I'm not sure it need to. What
kind of thing can come it? Perhaps a more literate programming style?
str."captialize every other letter"
Of course, that's really not much different than
str.captialize_every_other_letter
But, it does simplify:
item = "word"
str."captialize every other #{item}"
Furthermore, I wonder if we could go also blanket classes with
definitions for as many reasonable phrases applicatable. Can Ruby, or
any language for that matter, handle 1000s of methods per class?
T.