[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

a selfish ruby question

dave rose

9/1/2006 6:06:00 PM

why is it that:

>> class Akill
>> def astop(seq)
>> self.select{|astop| astop.first==seq}.collect
>> end
>> end
=> nil
>> grr.astop(b[0])
i get this error....
NoMethodError: private method `select' called for #<Akill:0x2dd01f8>
from (irb):86:in `astop'
from (irb):89
from ?:0
>>
...and when i do this:

class Akill
def astop(seq)
@arte.select{|astop| astop.first==seq}.collect
end
end

i don't....?

...and what is the difference in it's use if both worked...
i mean...what is the difference between making a method
that uses 'self' and one that uses a instance variable....

when would one to want to design a method with self and/or with a
instance variable?

....and even though i add to the Akill class:

attr_reader :arte, :stops, :rtes

...i still get these errors....

>> class Akill
>> def astop(seq)
>> self.select{|astop| astop.first==seq}.collect
>> end
>> end
=> nil
>> grr.arte.astop(b[0])
NoMethodError: undefined method `astop' for #<Array:0x2dd01b0>
from (irb):143
from :0
>> grr.astop([b0])
NameError: undefined local variable or method `b0' for main:Object
from (irb):144
from :0
>> grr.astop(b[0])
NoMethodError: private method `select' called for #<Akill:0x2dd01f8>
from (irb):140:in `astop'
from (irb):145
from :0
>>

--
Posted via http://www.ruby-....

8 Answers

Gavin Kistner

9/1/2006 6:30:00 PM

0

You can't have an explicit receiver for private methods. See below.

class Foo
def try1
something_private()
end

def try2
self.something_private()
end

private
def something_private()
puts "I'm doing private things!"
end
end

f = Foo.new
f.try1
#=> I'm doing private things!

f.try2
#=> tmp.rb:7:in `try2': private method `something_private' called for
#<Foo:0x282dd70> (NoMethodError)
#=> from tmp.rb:19

f.something_private
#=> tmp.rb:21: private method `something_private' called for
#<Foo:0x282ddd4> (NoMethodError)

dave rose

9/1/2006 6:54:00 PM

0

Phrogz wrote:
> You can't have an explicit receiver for private methods. See below.
in trying to understand this....
why is it then the Array.select instance method is private? here?....


--
Posted via http://www.ruby-....

Gavin Kistner

9/1/2006 10:01:00 PM

0

Dave Rose wrote:
> in trying to understand this....
> why is it then the Array.select instance method is private? here?....

You need to provide more details. You have explicitly stated that you
have another class, not an Array. Does your class inherit from Array?

Create the smallest program you can that showcases your problem, and
perhaps then we can help you.

Rick DeNatale

9/2/2006 9:09:00 PM

0

On 9/1/06, Dave Rose <bitdoger2@yahoo.com> wrote:
> Phrogz wrote:
> > You can't have an explicit receiver for private methods. See below.
> in trying to understand this....
> why is it then the Array.select instance method is private? here?....

It's not.

Quoting from your original post

> grr.arte.astop(b[0])
>NoMethodError: undefined method `astop' for #<Array:0x2dd01b0>
> from (irb):143
> from :0

Here grr.arte is returning an Array, and Array doesn't have an astop method.

> grr.astop([b0])
>NameError: undefined local variable or method `b0' for main:Object
> from (irb):144
> from :0

Did you mean to say b[0] instead of b0?

> grr.astop(b[0])
> NoMethodError: private method `select' called for #<Akill:0x2dd01f8>
> from (irb):140:in `astop'
> from (irb):145
> from :0

I guess that you've defined select as a private method in Akill or one
of it's superclasses. It's not complaining about select being a
private method of Array, but of Akill.

As has been pointed out, it's illegal to use an explicit receiver on
private methods.
This is the way that the Ruby runtime enforces privacy. So

self.publicMethod
is the same as just
publicMethod

but
privateMethod
works and
self.privateMethod raises an exception.
--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Logan Capaldo

9/2/2006 11:25:00 PM

0


On Sep 2, 2006, at 5:09 PM, Rick DeNatale wrote:

> I guess that you've defined select as a private method in Akill or one
> of it's superclasses. It's not complaining about select being a
> private method of Array, but of Akill.

This select is most likely Kernel#select (as in IO).


Bob Casanova

8/24/2010 5:47:00 PM

0

On Mon, 23 Aug 2010 18:04:30 -0400, the following appeared
in sci.skeptic, posted by Mr.B1ack <bw@barrk.net>:

>Bob Casanova <nospam@buzz.off> wrote:
>
>>On Mon, 23 Aug 2010 09:03:22 -0400, the following appeared
>>in sci.skeptic, posted by Mr.B1ack <bw@barrk.net>:
>>
>>>CNN reports that a team from a university in Georgia (usa)
>>>built a supercomputer out of PC graphics cards - which can
>>>do certain kinds of math really, really, fast. Their aim
>>>was to see how quickly passwords could be guessed.
>>>
>>>Their recommendation is that passwords be 12 characters
>>>long. Seems all 11-character passwords could be generated
>>>in 180 years using their setup, whereas 12-characters
>>>ballooned the guessing out to over 17,000 years.
>>>
>>>OK folks ... there's a MUCH better solution for both
>>>personal and corporate/govt systems. Limit how many
>>>bad passwords can be entered before there's an
>>>enforced time delay (or enforce a time delay after
>>>every password entry).
>>>
>>>Remote-access tools like the SSHD (secure shell daemon)
>>>ubiquitous to unix/linix servers have this option readily
>>>availible in the configuration file ... it need only be
>>>turned on. You can also limit how many instances of
>>>the daemon can be run concurrently - with a fair level
>>>of fine control. Unix/linux user accounts often have
>>>the same kind of bad-guess tools. Get it wrong three
>>>times or whatever and you're bumped off the system
>>>for a certain period.
>>>
>>>This would be dead easy to incorporate into even
>>>Winders-based servers and PCs.
>>>
>>>Even a ten or thirty SECOND delay after a few bad
>>>passwords would totally frustrate any sort of
>>>'guessing' attack. A five or six ASCII character
>>>password would take like forever to hit if you
>>>could only try three at a time and then had to
>>>wait awhile. Guessers would be better off trying
>>>"likely" passwords instead - and even then ...
>>>
>>>SO ... why the hell isn't this guess-rate-limiting
>>>scheme standard - and active by default - on ALL
>>>modern operating systems and server software ???
>>>Web servers, e-mail servers, whatever ... they
>>>ALL ought to be "guess-proofed". Not a hard
>>>patch by any means, a few lines of code. Add
>>>just a little extra IQ - check MAC addresses
>>>or attempted logins from any particualr domain -
>>>with just a couple dozen extra lines of code.
>>>
>>>EZ.
>>>
>>>So ... DO it already !
>>
>>Those are good ideas (and personally I additionally prefer
>>case-sensitive 20-character passwords that allow all ASCII
>>characters),
>
> The "problem" is pretty much all server-side,
> default settings that just let anybody shoot
> in millions of passwords as fast as their net
> connection permits.

Several of my more sensitive connections have both timeout
and multiple-try limits. But not all.

> For the most part it could
> literally be fixed in MINUTES. If a bank or
> other online biz loses your info due to this
> sort of attack, it's professional malpractice,
> incompetence - NOT because your password wasn't
> page 297 of War and Peace - and big lawsuits
> are in order.

Sure; that's why I said I agreed. But long random passwords
also help.

>>but what has this to do with s.s?
>
> It's scientific, but I'm skeptical. There's
> a lot of BS in computer security nowadays -
> much of it designed to scare people into
> parting with their money, privacy, convenience,
> or all three.
>
> Or has s.s. become all about Bigfoot
> and ghosts ?

From its inception s.s was intended to be about claims of
the paranormal. Lately (well, for quite a while) religion,
UFO whackos and general science denial have unfortunately
taken over most of it.
--

Bob C.

"Evidence confirming an observation is
evidence that the observation is wrong."
- McNameless

Blackwater

8/25/2010 2:48:00 PM

0

Bob Casanova <nospam@buzz.off> wrote:

>On Mon, 23 Aug 2010 18:04:30 -0400, the following appeared
>in sci.skeptic, posted by Mr.B1ack <bw@barrk.net>:
>
>>Bob Casanova <nospam@buzz.off> wrote:

>>>but what has this to do with s.s?
>>
>> It's scientific, but I'm skeptical. There's
>> a lot of BS in computer security nowadays -
>> much of it designed to scare people into
>> parting with their money, privacy, convenience,
>> or all three.
>>
>> Or has s.s. become all about Bigfoot
>> and ghosts ?
>
>From its inception s.s was intended to be about claims of
>the paranormal. Lately (well, for quite a while) religion,
>UFO whackos and general science denial have unfortunately
>taken over most of it.

You don't have to worry until people start
bragging about how many alien anal probes
they've recieved :-)

I've long since given up arguing with religious
nuts ... 'True Believers' are in their own little
hermetically-sealed alternative universe where
neither logic or evidence can penetrate. The
worst of the UFO wackos are also 'True Believers',
but instead of saying opponents or skeptics are
agents of Satan they'll say they're with The
Cover-up Conspiracy instead.

Bob Casanova

8/25/2010 3:54:00 PM

0

On Wed, 25 Aug 2010 10:47:38 -0400, the following appeared
in sci.skeptic, posted by Mr.B1ack <bw@barrk.net>:

>Bob Casanova <nospam@buzz.off> wrote:
>
>>On Mon, 23 Aug 2010 18:04:30 -0400, the following appeared
>>in sci.skeptic, posted by Mr.B1ack <bw@barrk.net>:
>>
>>>Bob Casanova <nospam@buzz.off> wrote:
>
>>>>but what has this to do with s.s?
>>>
>>> It's scientific, but I'm skeptical. There's
>>> a lot of BS in computer security nowadays -
>>> much of it designed to scare people into
>>> parting with their money, privacy, convenience,
>>> or all three.
>>>
>>> Or has s.s. become all about Bigfoot
>>> and ghosts ?
>>
>>From its inception s.s was intended to be about claims of
>>the paranormal. Lately (well, for quite a while) religion,
>>UFO whackos and general science denial have unfortunately
>>taken over most of it.
>
> You don't have to worry until people start
> bragging about how many alien anal probes
> they've recieved :-)

I suspect some of them actually have been probed, but not by
aliens. Well, make that "not by extraterrestrials".

> I've long since given up arguing with religious
> nuts ... 'True Believers' are in their own little
> hermetically-sealed alternative universe where
> neither logic or evidence can penetrate. The
> worst of the UFO wackos are also 'True Believers',
> but instead of saying opponents or skeptics are
> agents of Satan they'll say they're with The
> Cover-up Conspiracy instead.

I see you're familiar with some of the s.s loons... ;-)

BTW, I've set followups to the appropriate group; no reason
to continue polluting the others.
--

Bob C.

"Evidence confirming an observation is
evidence that the observation is wrong."
- McNameless