This is part of a online ruby quiz. Just doing it for my own
education, not on a test that I’m graded on.
assert_equal ([:r, :u, :b, :e, :q, :u, :e] __), [:b, :q]
I don’t understand the above because the blank is not right up against
the [:r, :u, :b, :e, :q, :u, :e] array. I’m not sure how to search
for whatever is supposed to be in the blank.
If someone could give me a hint rather than an answer it would be
appreciated.
Hey David,
Perhaps it has to do with certain operations that you can do with arrays
in
Ruby … Remember that Ruby provides syntactic sugar for certain kinds
of
methods … So, for e.g
def name= (name)
@name = name
end
can be invoked as
<some_object>.name = “David”
What Ruby does here is that it sees an assignment (name = “David”) and
looks for a method called name= (Note there is no whitespace between
name
and “=”).
I bring this up b/c it seems that you are thinking of a method that you
could use here (“I don’t understand the above because the blank is not
right up against
the … array”). And the solution lies in invoking a method on an array,
but
with the syntactic sugar applied.
Look at Class: Array (Ruby 1.9.3) and look at any
mathematical operators that might come in handy - see how they are to be
used.
Hope that helps.
Raju
Just the kind of pointer I was hoping for. Thanks.