Discussion: Lecture 1

September 3rd, 2009 Leave a comment Go to comments

Add comments here with questions and notes regarding Lecture 1.

  1. B Ruml
    September 4th, 2009 at 11:34 | #1

    On p21 of PR, Thomas says that in 1.9 "you can use name: value pairs to create a hash *if* the keys are symbols." Can you confirm my guess that this is an editing oversight and means that the new literal syntax *results in* keys that are symbols?

  2. September 4th, 2009 at 12:02 | #2

    See p. 71 of the PDF, and type these into irb:

    { dog: 'canine' }
    { :dog => 'canine' }

    I think the point is that in the colon syntax, the key must observe the naming conventions for symbols (start with a letter, etc.). I.e., the name would be appropriate for a symbol. Further, there is no way to embed a space (or non-alphanumeric chars) into the key name.

  3. September 5th, 2009 at 12:27 | #3

    A student asked: Why, when two objects are instantiated in a row, did the object_id skip a number?

    Answer:

    Live and learn. The Matz Ruby Interpreter (MRI) reserves odd object_id's for Fixnums. So try this in irb:

    0.object_id
    1.object_id
    2.object_id

    etc.

    If you do

    Object.new.object_id
    Object.new.object_id
    etc.

    you will see that the id's are allocated in a different range.

    JRuby -- which is what is used in the slides -- observes the MRI convention for Fixnum's, but allocates new object at the smallest object_id available.

    The backdrop for this is that while Fixnum's behave like objects, they are represented internally as immediate values, and the object_id is a "function" of the value.

    For some interesting discussion around this, see http://groups.google.com/group/ruby-talk-google/browse_thread/thread/2de0fb648d328ce9/83f16316f51904e6?show_docid=83f16316f51904e6

  4. Gabriel
    September 6th, 2009 at 07:52 | #4

    Is there a way to setup irb so that I can use ri directly in the irb console? (instead of always having to work with two bashes)

  5. September 6th, 2009 at 08:12 | #5

    @Gabriel

    Yes: create a file in your login directory called .irbrc (you can leave out the dot if you like).

    Then put this in there:

    def ri(*names)
    system(%{ri #{names.map {|name| name.to_s}.join(" ")}})
    end

    Save the file, and then type from within irb:

    ri "String#reverse"

    (You will need the quotation marks if there is a syntactically important bit of Ruby -- such as the # -- in the request.)

    There are fancier ways to do this so you don't leverage the "system" call, but I think this is good enough for now.

    This used to be in the Pickaxe, but I can't find it in the new edition.

  6. Ron Newman
    September 6th, 2009 at 09:15 | #6

    I found that I already had an .irbrc file -- I guess this is put in by default the first time you run irb?

    It contains just this:
    IRB.conf[:IGNORE_EOF] = true

  7. September 6th, 2009 at 10:27 | #7

    @Ron Newman

    Interesting. After my setup, there is no .irbrc.

    To learn about IRB.conf, take a look at chapter 18 in the Pickaxe.

  8. Virginia
    September 7th, 2009 at 17:34 | #8

    Anybody else having trouble accessing the video for lecture 1? I keep getting a connection error at this link: http://cm.dce.harvard.edu/2010/01/12923/L01/seg1/index_FlashSingleHighBandwidth.html.

  9. September 7th, 2009 at 17:42 | #9

    @Virginia

    I just started the video and it worked for me.

    There is a phone number for technical support: 617-998-8571.

    I believe students are allowed/encouraged to call this number: If you do, post any results here.

  10. DJ
    September 9th, 2009 at 16:31 | #10

    Interesting...I just checked the DCE website (http://cm.dce.harvard.edu/2010/01/12923/liveClassroom.shtml) and it says "no videos available at this time." Anyone know what's going on?

  11. DJ
    September 9th, 2009 at 16:38 | #11

    @DJ
    Never mind...had the wrong URL!

  12. Tom Maciejczyk
    September 12th, 2009 at 15:52 | #12

    If anyone is having problems with the embedded ruby in the slides - make sure you have Java installed. (Formatted my machine, couldn't figure out why it wasn't working)

    http://www.java.com/en/download/

  1. No trackbacks yet.