From: Gennady Date: 2003-05-06T09:49:44+09:00 Subject: Variable/Method ambiguity This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C3132E.1224A280 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Pickaxe p.212 explains the subject well enough, however here's an = interesting case: class Test def name=3D(name) puts "Called 'name=3D' ..." end def test name =3D "aaa" end end Test.new.test I would expect to see "Called 'name=3D' ...", as Ruby can realize here = that method "name=3D" is available and call it. However, nothing is = printed, meaning that an assignment to local variable "name" took place. Is it only me who thinks that such behaviour is inconsistent? Actually, I am trying to use Ruby as some description language. I eval = file --- product { name =3D "Some name" description =3D "Some description" ... } --- in the binding of the class: class Registry def product @product =3D Product.new yield if block_given? ... end def name=3D(name) @product.setName(name) end def description=3D(description) @product.setDescription(description) end def process(file) contents =3D File.readlines(file).join eval contents, binding, file end end Alas, it does not work as I would expect :-( Thanks in advance for any input, Gennady. ------=_NextPart_000_0007_01C3132E.1224A280 Content-Type: text/html; charset="koi8-r" Content-Transfer-Encoding: quoted-printable
Pickaxe p.212 explains the subject well = enough,=20 however here's an interesting case:
 
class Test
  def name=3D(name)
    puts "Called = 'name=3D'=20 ..."
  end
  def test
    name =3D = "aaa"
  end
end
 
Test.new.test
 
I would expect to see "Called 'name=3D' = ...", as Ruby=20 can realize here that method "name=3D" is available and call it. = However, nothing=20 is printed, meaning that an assignment to local variable "name" took=20 place.
 
Is it only me who thinks that such = behaviour is=20 inconsistent?
 
Actually, I am trying to use Ruby = as some=20 description language. I eval file
---
product {
  name =3D "Some = name"
  description =3D "Some=20 description"
  ...
}
---
in the binding of the = class:
 
class Registry
  def product
    @product =3D=20 Product.new
    yield if=20 block_given?
    ...
  end
  def name=3D(name)
   =20 @product.setName(name)
  end
  def = description=3D(description)
   =20 @product.setDescription(description)
  end
  def process(file)
    contents =3D=20 File.readlines(file).join
    eval contents, = binding,=20 file
  end
end
 
Alas, it does not work as I would = expect=20 :-(
 
Thanks in advance for any = input,
Gennady.
------=_NextPart_000_0007_01C3132E.1224A280--