Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Adding properties to a method?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jonT  
View profile  
 More options Feb 5 2006, 1:05 pm
Newsgroups: comp.lang.ruby
From: "jonT" <j...@Tippell.com>
Date: 5 Feb 2006 10:05:41 -0800
Local: Sun, Feb 5 2006 1:05 pm
Subject: Adding properties to a method?
Hi,

I'd like to be able to do the following:

class Method; attr_accessor :foo; end
def bar; "some_res"; end
method(:bar).foo=1

method(:bar).foo #= 1

Of coures what i'd actually get is:
method(:bar).foo #= nil

because method(:bar) returns a new object each time.

Is it possible to bind properties to a method definition? If so, how?

Thanks,
Jon


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Britt  
View profile  
 More options Feb 5 2006, 1:29 pm
Newsgroups: comp.lang.ruby
From: James Britt <jame...@neurogami.com>
Date: Mon, 6 Feb 2006 03:29:56 +0900
Local: Sun, Feb 5 2006 1:29 pm
Subject: Re: Adding properties to a method?

jonT wrote:
> Hi,

> I'd like to be able to do the following:

> class Method; attr_accessor :foo; end
> def bar; "some_res"; end
> method(:bar).foo=1

> method(:bar).foo #= 1

> Of coures what i'd actually get is:
> method(:bar).foo #= nil

> because method(:bar) returns a new object each time.

A String, in your example.  Do you want the string  to respond to the
message 'foo=' ?

> Is it possible to bind properties to a method definition? If so, how?

What do you mean by "bind" and "properties"?

--
James Britt

"Programs must be written for people to read, and only incidentally
  for machines to execute."
   - H. Abelson and G. Sussman
   (in "The Structure and Interpretation of Computer Programs)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Trans  
View profile  
 More options Feb 5 2006, 1:42 pm
Newsgroups: comp.lang.ruby
From: "Trans" <transf...@gmail.com>
Date: 5 Feb 2006 10:42:53 -0800
Local: Sun, Feb 5 2006 1:42 pm
Subject: Re: Adding properties to a method?
You can check out Facets' kernel/method.

T.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jonT  
View profile  
 More options Feb 5 2006, 1:45 pm
Newsgroups: comp.lang.ruby
From: "jonT" <j...@Tippell.com>
Date: 5 Feb 2006 10:45:01 -0800
Local: Sun, Feb 5 2006 1:45 pm
Subject: Re: Adding properties to a method?

>> Of coures what i'd actually get is:
>> method(:bar).foo #= nil
>> because method(:bar) returns a new object each time.
>A String, in your example.  Do you want the string to respond to the
>message 'foo=' ?

method(:bar)
# => <Method: Object#bar>
method(:bar).class
# => Method

method(:bar) actually returns a method object.

>What do you mean by "bind" and "properties"?

Sorry. By bind I meant simply to set the value of a properety in the
usual way. By property I mean property: a public field.

Essentially what I'm aiming to do is to have some way of storing data
about a method (which is either private to Object or a member of some
class or module) such that it is publicly available. Example:

def cd(dir)
        FileUtils.cd(dir.path)
        nil
end
method(:cd).args_classes={0=>JDir}

not terribly Ruby like but you get the picture.

Jon


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jonT  
View profile  
 More options Feb 5 2006, 2:28 pm
Newsgroups: comp.lang.ruby
From: "jonT" <j...@Tippell.com>
Date: 5 Feb 2006 11:28:15 -0800
Local: Sun, Feb 5 2006 2:28 pm
Subject: Re: Adding properties to a method?
    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Hodel  
View profile  
 More options Feb 6 2006, 2:33 pm
Newsgroups: comp.lang.ruby
From: Eric Hodel <drbr...@segment7.net>
Date: Tue, 7 Feb 2006 04:33:04 +0900
Local: Mon, Feb 6 2006 2:33 pm
Subject: Re: Adding properties to a method?
On Feb 5, 2006, at 10:08 AM, jonT wrote:

> class Method; attr_accessor :foo; end
> def bar; "some_res"; end
> method(:bar).foo=1

> method(:bar).foo #= 1

> Of coures what i'd actually get is:
> method(:bar).foo #= nil

> because method(:bar) returns a new object each time.

Of course!  It may not be the same method.  Another thread may  
overwrite bar with a new implementation.

--
Eric Hodel - drbr...@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google