Re: How to create "def method(item)= (value)" ?
- From: Ken Bloom <kbloom@xxxxxxxxx>
- Date: Wed, 30 Apr 2008 09:09:35 -0500
On Wed, 30 Apr 2008 07:22:30 -0500, Iñaki Baz Castillo wrote:
Hi, is it not possible to create a method to use in this way?
my_object.param("tag") = "new_value"
How to define that method? I've tryed something as:
def param(name)= (value)
@params[name] = value
end
but obviously I get error:
SyntaxError: compile error
syntax error, unexpected '='
Is there some way? Thanks a lot.
def initialize
@params={}
end
def param
@params
end
my_object.param["tag"]="new value"
If you need some sort of validation, you can have param return some other
class that defines [] and []= and does the necessary validation, and you
can even set up an easy method for defining the param attribute to do all
of that if need be.
--
Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
.
- Follow-Ups:
- Re: How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- Re: How to create "def method(item)= (value)" ?
- References:
- How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- How to create "def method(item)= (value)" ?
- Prev by Date: Re: Search string for occurneces of words stored in array
- Next by Date: Re: How to create "def method(item)= (value)" ?
- Previous by thread: Re: How to create "def method(item)= (value)" ?
- Next by thread: Re: How to create "def method(item)= (value)" ?
- Index(es):
Relevant Pages
|