Quick One

1 view
Skip to first unread message

Joel Turnbull

unread,
Jul 31, 2013, 12:05:27 AM7/31/13
to cincin...@googlegroups.com

reject!{|p| p == self}

Is there a better way to write that?

Joel

Jim Weirich

unread,
Jul 31, 2013, 8:03:23 AM7/31/13
to cincin...@googlegroups.com

On Jul 31, 2013, at 12:05 AM, Joel Turnbull <joel...@gmail.com> wrote:

>
> reject!{|p| p == self}
>
> Is there a better way to write that?

Whoa! Mind slightly blown here. So we have a container, and we iterate through the container and reject elements of the container that are the entire container itself (and then set the container to the new container-less result).

I suppose that's possible, e.g.

a = []
a[0] = a
a # => [[...]]
def a.remove_self; reject! { |p| p == self }; end
a.remove_self
a # => []

Oh, to answer your question, I don't know of a demonstrably better way to write that line.

--
-- Jim Weirich / neo
-- Chief Scientist

Joel Turnbull

unread,
Jul 31, 2013, 8:27:44 AM7/31/13
to cincin...@googlegroups.com

Oops, I wasn't really calling reject on self in the code I was working on, but that's the question I posed here, wasn't it? :P

I was just wondering if there was a more elegant way to write that block that I didn't know about.

Thanks Jim!

--

---
You received this message because you are subscribed to the Google Groups "Cincinnati.rb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cincinnatirb...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply all
Reply to author
Forward
0 new messages