[#407] New feature for Ruby? — Clemens.Hintze@...

Hi all,

27 messages 1999/07/01
[#413] Re: New feature for Ruby? — matz@... (Yukihiro Matsumoto) 1999/07/01

Hi Clemens,

[#416] Re: New feature for Ruby? — Clemens Hintze <c.hintze@...> 1999/07/01

On Thu, 01 Jul 1999, Yukihiro Matsumoto wrote:

[#418] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/01

Hi

[#426] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/02

Hi,

[#440] Now another totally different ;-) — Clemens Hintze <c.hintze@...>

Hi,

21 messages 1999/07/09
[#441] Re: Now another totally different ;-) — matz@... (Yukihiro Matsumoto) 1999/07/09

Hi,

[#442] Re: Now another totally different ;-) — Clemens Hintze <c.hintze@...> 1999/07/09

On Fri, 09 Jul 1999, you wrote:

[#443] — Michael Hohn <hohn@...>

Hello,

26 messages 1999/07/09
[#444] interactive ruby, debugger — gotoken@... (GOTO Kentaro) 1999/07/09

Hi Michael,

[ruby-talk:00412] Re: Ruby regular expression incompatibility/bug

From: matz@... (Yukihiro Matsumoto)
Date: 1999-07-01 07:39:09 UTC
List: ruby-talk #412
Hi,
In message "[ruby-talk:00405] Ruby regular expression incompatibility/bug"
    on 99/06/29, Julian R Fondren <julian@cartotech.com> writes:

|Ruby:
|% ruby
|foo = '"'
|foo =~ s/"/x/
|print "#{foo}\n"
|--> -:3: undefined local variable or method `s' for #<Object:0x4012ced4>
|---> (NameError)

As answered by Cle, 

  foo =~ s/"/x/

is not a valid Ruby script; it should be 

  foo.sub!(/"/, "x")

to do your intention.  

Notice that no syntax error reported?  Because

  foo =~ s/"/x/
  print "#{foo}\n"

was considered as

  foo =~ s/"/x/\nprint "#{foo}\n"

Intresting?  `#{foo}\n"' was ignored, because it was considered as a
comment, and `s/"/x/\nprint "' was considered was local variable or
argument-less method call `s' devided by the string "/x/\nprint ".

|Ruby using irb (clearer):
|% ruby -r irb -e1
|irb(main):001:0> foo = '"'
|"\""
|irb(main):002:0> foo =~ s/"/x/
|irb(main):003:0"                # what!?

Now you know why irb gave you prompt for string input.

                                                matz.

In This Thread

Prev Next