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?
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.
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.
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)
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?
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.
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
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)
@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.
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
@Ron Newman
Interesting. After my setup, there is no .irbrc.
To learn about IRB.conf, take a look at chapter 18 in the Pickaxe.
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.
@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.
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?
@DJ
Never mind...had the wrong URL!
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/