Help me condence my code?

Simon Schuster wrote:

putting it into phrase-test.rb and running it that way I get:

ph-test.rb:3: undefined method `delete_at' for nil:NilClass
(NoMethodError)
        from ph-test.rb:10:in `each_with_index'
        from ph-test.rb:1:in `each'
        from ph-test.rb:1:in `each_with_index'
        from ph-test.rb:1

and relatedly, going through step by step I get:

023:0> end.delete_at(-1)
SyntaxError: compile error
(irb):23: syntax error, unexpected kEND
end.delete_at(-1)

I've never seen tacking things onto end before! is this possible?

hmm, well I guess that means that the delete_at(-1) isn't being called
on an array, so the return value of that isn't what I expected. But, to
answer the question it is possible to tack things on the end like that.
Take that delete_at(-1) off then run it and call f.class, it probably
says NilClass, but in the case it says Array, then I don't know back to
the books for me :slight_smile:

~Jeremy

···

--
Posted via http://www.ruby-forum.com/\.

Hah! Writing code that actually _does_ stuff doesn't seem scary to
you, but writing tests, that don't even need to do anything but make
sure you code does the right thing, (and you don't even have to write
the code first), is the scary, murky seeming thing? Writing code
without tests is murky. Writing code without tests is scary. Tests are
your friends.

···

On 9/6/07, Simon Schuster <significants@gmail.com> wrote:

eek. I've never written a unit test before. that's all incredibly
murky territory.. not only am I new to ruby, but new to programming in
general. I'll get around to it someday, I think. it just seems scary.
:slight_smile:

John Mettraux wrote:

···

On 9/7/07, Lloyd Linklater <lloyd@2live4.com> wrote:

Jeremy Woertink wrote:
> end.delete_at(-1)

OMG! You can call methods in an end??? I have lived far to long in the
scalar world! When would you do such a thing?

irb(main):004:0> [1, 2].collect do |i| i+3; end.join " : "
=> "4 : 5"

The method call is not on the "end" but on the result of the method
using the block that the "end", well, 'closes'. Very functional.

That is just too cool for words. Thanks for getting back to me!
--
Posted via http://www.ruby-forum.com/\.