Core Ruby Classes

  • jaymcgavren

Oops, a subscription is required to view this video. You can enroll now to watch, or try out all that Code School has to offer with a free two-day Hall Pass.


Clint Lenard said

Great video! I'd love to see more like these, focused on just Ruby (not rails).

David Douglas said

same goes for %S, and there are probably others

David Douglas said

%W can use any delimiter you like, not just "/". it could be %W[ ... ], etc

David Douglas said

using global methods is not required to use the bang! methods.

string.strip! works just fine

David Douglas said

gsub = "global substitute" (replaces globally) sub = "(local) substitute)"

thousander said

Very helpful. Thanks!

spilth said

Nicely done! It's always good to be reminded of/introduced to methods like these.

Eric Raio said

Great screencast! Learned some new tricks that I can apply at work tomorrow. Thanks Jay!!


Jay McGavren said

@mikestok right you are - the += is a little misleading. This would probably have been a better example:

sum = scores.inject(0) {|sum, value| sum + value}

Good catch!

Mike Stok said

In the explanation of inject using bowling scores in a season it seems redundant to use sum += value at the end of the inject block as the inject will put the return value of the block into the "accumulator", so

sum = scores.inject(0) do |accumulator, score| accumulator + score end

works and might give more insight into how inject works.


Jay McGavren gives an overview of a few Ruby Core Classes, covering examples from the String, Array, Hash, and Enumerable classes. If the Ruby language still feels new for you, this is definitely worth watching.