ruby course confusion

Discussion in 'Ruby' started by Alex Combas, Feb 12, 2006.

  1. Alex Combas

    Alex Combas Guest

    Working my way through the "ruby course"
    http://ruby-doc.org/docs/Immersive Ruby programming course/RubyCourse=
    _1.0-1.pdf

    I was wondering if anyone else finds this tutorial a little confusing.
    Its really good in parts, but other parts are really unclear but maybe
    its just me.

    For example:
    ~~~
    find_it
    Write a function find_it that takes an array of strings and a block.
    The block should take two parameters and return a boolean value.
    The function should allow to implement longest_string, shortest_string,
    and other functions by changing the block.
    ~~~

    Sorry, this just seems really muddled.
    Is find_it a class, method, or what?
    What is the point of the boolean that the block needs to return?

    I asume that find_it is a class, and longest_string and shortest_string
    are object methods, and the array and the block are passed when
    the class is initialized, but I feel like I'm missing something.

    --
    Alex Combas
    http://noodlejunkie.blogspot.com/
     
    Alex Combas, Feb 12, 2006
    #1
    1. Advertising

  2. On Feb 12, 2006, at 5:23, Alex Combas wrote:

    > For example:
    > ~~~
    > find_it
    > Write a function find_it that takes an array of strings and a block.
    > The block should take two parameters and return a boolean value.
    > The function should allow to implement longest_string,
    > shortest_string,
    > and other functions by changing the block.
    > ~~~
    >
    > Sorry, this just seems really muddled.
    > Is find_it a class, method, or what?
    > What is the point of the boolean that the block needs to return?
    >
    > I asume that find_it is a class, and longest_string and
    > shortest_string
    > are object methods, and the array and the block are passed when
    > the class is initialized, but I feel like I'm missing something.


    A function in this case would be a method. The two terms are often
    used interchangeably, despite theoretical quibbles that they're not
    quite the same thing; a lambda expression is also a function, for
    instance.

    The point of the block is that you're attempting to write a method
    that can be used as a general implementation of several other
    methods, depending on the contents of the block. The boolean return
    value of the block is actually a very small hint, following from the
    fact that finding the shortest/longest element of an array is very
    closely related to sorting the array.

    Anyway, here's the initial problem restated:

    > Write a method find_it that takes as parameters:
    > - an array of strings
    > - a block
    > The block should take two parameters and return a boolean value.
    >
    > You should be able to implement longest_string and shortest_string
    > simply by changing the block provided to find_it. In other words,
    > the implementation of longest_string and shortest_string will
    > consist only of a call to find_it with a particular block:
    >
    > def longest_string (arr)
    > find_it(arr) { ... }
    > end
    >
    > def shortest_string (arr)
    > find_it(arr) { ... }
    > end



    As for the document being muddled, I read a fair bit of it, and it
    strikes me that the amount of apparent muddle would depend on your
    previous exposure to programming in general.

    It's a bit of a catch with teaching/learning programming; it uses
    very jargony language without the same formalism you get in maths. A
    method in one language is a function in another is a procedure in a
    third and doesn't even exist as a concept in a fourth language. This
    vocabulary issue really does put a hitch in learning programming,
    since to know what a term really means, you need to know the theory
    behind it, for which you need to know what the terms mean.... and I
    think you see the problem. The best way to deal with this obstacle
    it is to jump right in, and ask questions when you're stumped. Which
    you seem to be doing, so good on you.


    Hope that helps.

    matthew smillie.



    ----
    Matthew Smillie <>
    Institute for Communicating and Collaborative Systems
    University of Edinburgh
     
    Matthew Smillie, Feb 12, 2006
    #2
    1. Advertising

  3. Alex Combas

    Alex Combas Guest

    On 2/11/06, Matthew Smillie <> wrote:

    Thanks Matthew, I appreciate you taking the time
    to reword this for me, but there is one part that is
    still bothering me.

    > > The block should take two parameters and return a boolean value.


    Its the thing with the boolean that I dont get. This seems to be asuming
    some prior knowledge of a particular ruby method.
    I've searched Array and String and dont see anything that fits.

    What is this boolean supposed to show? Booleans can me on/off
    true/false, found/not_found, or many other things.

    If the guide just stated what the boolean is for, or even better what
    method they want used that returns a boolean I'm sure this would
    be a rather simple problem.

    Finding the longest or shortest string in an array is so trivial.
    This really seems more like an exercise on howto structure blocks
    and pass variables to methods.

    result =3D arr.sort_by {|w| w.length};
    shortest,longest =3D result[0],result[-1]
    --
    Alex Combas
    http://noodlejunkie.blogspot.com/
     
    Alex Combas, Feb 12, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Schroeder

    Ruby Course

    Brian Schroeder, Jul 19, 2004, in forum: Ruby
    Replies:
    3
    Views:
    124
    Robert Feldt
    Jul 20, 2004
  2. Brian Schröder

    A ruby course

    Brian Schröder, Oct 4, 2004, in forum: Ruby
    Replies:
    40
    Views:
    415
    Brian Candler
    Oct 7, 2004
  3. Brian Schröder

    [ANN] Ruby Course 1.0

    Brian Schröder, Oct 9, 2004, in forum: Ruby
    Replies:
    5
    Views:
    126
    Curt Hibbs
    Oct 10, 2004
  4. Damphyr

    Crash Course on Speed for Ruby

    Damphyr, Nov 20, 2005, in forum: Ruby
    Replies:
    8
    Views:
    134
    Stephan Mueller
    Nov 21, 2005
  5. David A. Black
    Replies:
    0
    Views:
    136
    David A. Black
    Mar 27, 2007
Loading...

Share This Page