Simple iteration in a function problem

unknown wrote:

Hi –

On Sat, 2 Dec 2006, Blake M. wrote:

def component(uniqueId) # note: uniqueId is a string
@components.find { |comp| comp.getUniqueId == uniqueId }
end
end

=========================================================
class SearchWidgetComponent
:attr_reader :uniqueId

No : on attr_reader; it’s a method:

attr_reader :uniqueID

def getUniqueId
@uniqueId
end

You’ve now got two “get” methods for @uniqueID: the one attr_reader
created (which will be called uniqueID), and the one you’ve written.

end

=============================
class SearchWidgetComparisonComponent

def getUniqueId
super

super won’t work here, unless this class is a subclass of
SearchWidgetComponent. And if it is a subclass, it will have that
method anyway. And… you don’t need the method in the first place,
because of attr_reader :slight_smile:

end
end

Also, you need a way to set as well as get your uniqueID values,
unless they’re going to be something inherent in the object (the
object’s object_id). Do you want attr_writer too?

David
Noted, and changed. Sorry if I’m dragging this out, I know I left out a
couple details in the code I showed. Indeed
SearchWidgetComparisonComponent does, and has been extending
SearchWidgetComponent. My new code is like this:

class SearchWidget
def initialize
@components = Array.new
end

def add_component(component)
@components << component # these will always be subclass of
SearchWidgetComponent
end

def printcomps # i call this from index.rhtml, and it prints correctly
the 2 different component ids
str = “”
@components.each_with_index do |comp, index|
str += @components[index].uniqueId
end
str
end

def component(uniqueId)
@components.find { |comp| comp.uniqueId == uniqueId }
end
end

==================================
class SearchWidgetComponent
attr_accessor :uniqueId

def initialize(label, uniqueId) # see I pass a string as the id when I
init
@label = label
@uniqueId = uniqueId
end
end

class SearchWidgetComparisonComponent < SearchWidgetComponent
def initialize(label, uniqueId)
super(label, uniqueId)
@dbFields = Array.new
@showCalendar = false;
end
end

in my index.rhtml, I have (please note I’ve added comments below only to
this post, they are not in the source):
<%= @sw.printcomps %> # prints “swCompareComp1”, and “anoth” (my two
unique ids)

should return a SearchWidgetComparisonComponent

<% @obj = @sw.component(“swCompareComp1”) %>

call method stylize() on the object

<%= @obj.stylize(“sdbfPulldown”, “scPulldown”, “svfClass”)%>

; however, the line that calls the stylize() method returns an error
saying " NoMethodError in Region#index…You have a nil object when
you didn’t expect it! The error occured while evaluating nil.stylize"

Thanks ahead for the help yo. I’ve been tearin my hair out for 5 hours
now.

Paul L. wrote:

Blake M. wrote:

Why can’t it be a string, I can use whatever I want to identify an
object.

  1. It should not be a string because your goal is to compare two object IDs,
    not strings. You are calling the variable “uniqueId”, don’t you think it
    should be what it says it is? BTW use the Rubyish “unique_id” rather than
    “uniqueId”.

If the ID is coming from outside the program (a file say) or if the ID
needs to persist, then using a string makes sense. Ruby object ids don’t
persist.

Hi –

On Sat, 2 Dec 2006, Paul L. wrote:

Blake M. wrote:

Posting bits and pieces of code, but never a short working example, is a
sure way to assure that this thread will go on forever.

Why can’t it be a string, I can use whatever I want to identify an
object.

  1. I can see why this thread goes on so long – instead of meeting my
    request, you just changed the subject.

Paul, could you please stop being so confrontational? Your standards
are no higher than those of a lot of very accomplished programmers,
authors, and teachers on this list who do not find it necessary or
productive (neither of which it is) to adopt the kind of unpleasantly
didactic – or, at many times, simply unpleasant – tone that you
favor.

It seems to me that you might well have interesting things to say
about Ruby and programming in general, but right now they’re smothered
in a mass of hostile, judgmental rhetoric. My advice would be just to
jettison it. If you want someone to clarify something, just ask them
what they meant. Don’t add a lecture about their behavior.
Similarly, if you think someone has done something inadvisable, just
say so. Don’t start with, “What? You did THAT?!” (or equivalent).

Thanks –

David

On Dec 1, 2006, at 8:32 PM, [email protected] wrote:

Why can’t it be a string, I can use whatever I want to identify an
favor.

It seems to me that you might well have interesting things to say
about Ruby and programming in general, but right now they’re smothered
in a mass of hostile, judgmental rhetoric. My advice would be just to
jettison it. If you want someone to clarify something, just ask them
what they meant. Don’t add a lecture about their behavior.
Similarly, if you think someone has done something inadvisable, just
say so. Don’t start with, “What? You did THAT?!” (or equivalent).

Yes, please.

James Edward G. II

[email protected] wrote:

/ …

Why can’t it be a string, I can use whatever I want to identify an
object.

  1. I can see why this thread goes on so long – instead of meeting my
    request, you just changed the subject.

Paul, could you please stop being so confrontational?

There isn’t one word about Ruby in your post. That places you post in a
well-known category, one that should always be marked [OT].

Your standards are no higher …

On the contrary, as I just demonstrated.

Paul L. schrieb:

[email protected] wrote:

Paul, could you please stop being so confrontational?

There isn’t one word about Ruby in your post. That places you post in a
well-known category, one that should always be marked [OT].

David’s post was about your behaviour here on ruby-talk, which is quite
on-topic.

Your standards are no higher …

On the contrary, as I just demonstrated.

To me, yours don’t seem to be higher, just different.

Regards,
Pit

On Sat, 2 Dec 2006, Paul L. wrote:

Paul, could you please stop being so confrontational?

There isn’t one word about Ruby in your post. That places you post in a
well-known category, one that should always be marked [OT].

I’ll take that as a “No.”

Actually my main message isn’t to you (it’s been pointed out to me
that you’re a career troll, doing the same thing in a number of online
forums). It’s to the list in general, and especially the newcomers
who might be put off: Hang in there! We’re not all like this. You
can get lots of welcome and help from lots of very nice experts here.

David

Pit C. wrote:

Paul L. schrieb:

[email protected] wrote:

Paul, could you please stop being so confrontational?

There isn’t one word about Ruby in your post. That places you post in a
well-known category, one that should always be marked [OT].

David’s post was about your behaviour here on ruby-talk, which is quite
on-topic.

Yes, but the [OT] can be used to allow filtering posts based on their
relevance to the newsgroup’s topic, not the meta-topic of topicality
(always topical).

Your standards are no higher …

On the contrary, as I just demonstrated.

To me, yours don’t seem to be higher, just different.

Thank you. You instinctively understood a point I may have difficulty
making
other posters understand.

[email protected] wrote:

request, you just changed the subject.

Paul, could you please stop being so confrontational?

There isn’t one word about Ruby in your post. That places you post in a
well-known category, one that should always be marked [OT].

I’ll take that as a “No.”

Which “No” did you have in mind? In essence my reply, by virtue of
existing,
says “yes.”

Your post’s meta-message is that there are times when a critical post in
appropriate, and (in a morally neutral universe) individuals decide
those
times on their own. I happen to agree, and I have shown that I agree by
replying.

Now that I have told you that I understood and accepted your post and
its
underlying rationale, what remains undetermined is whether you
understand
and accept mine.

Actually my main message isn’t to you (it’s been pointed out to me
that you’re a career troll, doing the same thing in a number of online
forums).

Nice ad-hominem touch, one that reinforces my point that we are free to
be
as critical as we like, even when we depart reality in doing so. But
this
is a symmetrical principle – it applies to all equally.

It’s to the list in general, and especially the newcomers
who might be put off: Hang in there! We’re not all like this. You
can get lots of welcome and help from lots of very nice experts here.

Including from me, as a balanced reading my posts proves.

James Edward G. II wrote:

It seems to me that you might well have interesting things to say
about Ruby and programming in general, but right now they’re smothered
in a mass of hostile, judgmental rhetoric. My advice would be just to
jettison it. If you want someone to clarify something, just ask them
what they meant. Don’t add a lecture about their behavior.
Similarly, if you think someone has done something inadvisable, just
say so. Don’t start with, “What? You did THAT?!” (or equivalent).

Yes, please.

James, thanks for pitching into a critical response, a right we all
share
equally. Each of us decides based on personal standards when a critical
post seems appropriate, and no on should expect to be able to judge
whether
another person’s timing is at fault. It seems you agree.

Hi Blake –

On Sun, 3 Dec 2006, Blake M. wrote:

relevance to the newsgroup’s topic, not the meta-topic of topicality
(always topical).
What does [OT] stand for, and is the appropriate tagging to put it in
the subject? Also, perhaps my post should have been in the Ruby on
Rails forum instead, since I am working on an ROR project, but I thought
it was a general enough Ruby question, so I posted there. Cheers, and
thanks for the help. I think this is the most useful Ruby forum I’ve
come across.

It means “off-topic”, and don’t worry; it wasn’t added in reference to
your original post.

David

[email protected] wrote:

Paul, could you please stop being so confrontational?

There isn’t one word about Ruby in your post. That places you post in a
well-known category, one that should always be marked [OT].

David’s post was about your behaviour here on ruby-talk, which is quite
on-topic.

Yes, but the [OT] can be used to allow filtering posts based on their
relevance to the newsgroup’s topic, not the meta-topic of topicality
(always topical).
What does [OT] stand for, and is the appropriate tagging to put it in
the subject? Also, perhaps my post should have been in the Ruby on
Rails forum instead, since I am working on an ROR project, but I thought
it was a general enough Ruby question, so I posted there. Cheers, and
thanks for the help. I think this is the most useful Ruby forum I’ve
come across.

Blake M. wrote:

relevance to the newsgroup’s topic, not the meta-topic of topicality
(always topical).
What does [OT] stand for, and is the appropriate tagging to put it in
the subject?

It actually stands for “Off Topic”, but in a case like this it is
entirely
appropriate to allow filtering by people who don’t care to read about
the
meta-topic of topicality.

Blake M. wrote:

What does [OT] stand for, and is the appropriate tagging to put it in
the subject?

Off-topic, either with respect to the mailing list, or to the thread.
Technically Not Proper ™, but some of the more amusing derailings
(punfights, oldbie ramblings) are a nice diversion, and don’t seem to be
bullied off.

Also, perhaps my post should have been in the Ruby on
Rails forum instead, since I am working on an ROR project, but I thought
it was a general enough Ruby question, so I posted there.

As far as I know, the RoR forum is for questions related to the Rails
API (Where do I put partial templates, how do I connect different
ActiveRecord classes to different databases, that sort of questions.).
Questions that are “general enough” even if they happen to be in a RoR
context should indeed go here.

Cheers, and
thanks for the help. I think this is the most useful Ruby forum I’ve
come across.

This is the one gatewayed to the newsgroup and the mailing list (which,
I believe, came first), therefore The Big One, so you’re most likely to
find the widest reception and the core Rubydom listening in.

David V.