> I am having fun learning Ruby at http://rubymonk.com I like this type of lessons ;-) - Yukihiro Matsumoto, Creator of Ruby
Uhhh guys? If the creator of Ruby is taking lessons about Ruby how can this site even exist???!!
Also related is http://rubymonk.com which is a good start for someone who may not be ready for Ruby Warrior yet. I'm a fairly accomplished programmer, and had done a bit of ruby hacking, but still enjoyed Ruby Warrior.
All are free. I've used and learned from them all. And...they're all fun :) Enjoy!
Alternatively, you can call it with a do...end
or {}
block.
def calculation(a, b) yield(a, b) end
puts calculation(5, 6) { |a, b| a + b } # addition puts calculation(5, 6) { |a, b| a - b } # subtraction
Source: http://rubymonk.com/learning/books/4-ruby-primer-ascent/chapters/18-blocks/lessons/54-yield
> Did you explore the ruby source code?
Haha, no... that's a little bit beyond me. Mostly, I've just been working with ruby (and many of its amazing-yet-weird metaprogramming features) for four or five years now. A lot of my work has involved writing methods that accept a block and then do unexpected things with it (like storing it for later, or executing it in a totally different context), so I've had some time to get an understanding of how ruby handles them.
If you're interested in getting more hands-on with blocks and other fun and crazy ruby concepts, I recommend rubymonk.com, especially their Metaprogramming Ruby and Metaprogramming Ruby: Ascent courses.
>Edit: It also doesn't help too much when learning all the different ways to do the same thing. That might just be me though
Welcome to Ruby.
You'll be introduced to several ways of doing the same thing. All else being equal, use the way that makes the most sense to you. Still be aware of the other ways. You may grow to like them, and other people will probably use them.
Procs, blocks, and lamdas are tough at first. They'll seem tough for awhile too. Try this:
http://www.reactive.io/tips/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
And this:
Personally, I don't think going back and rereading some material is the way to go. Text introduces you to concepts, coding teaches you concepts.
Read through the Ruby Monk stuff, and then get some practice in. Find some simple programs you've already made, and change them to work using the new concepts. Even if you normally wouldn't ever use procs or lambdas in them. You just need to master the idea of them. Once you do that you'll recognize when you actually want to use them.
I made my first relatively big thing in Java, but by then I had learned enough programming so I didn't use any tutorial while learning Java.
I also don't think Java is a very good beginners language. Learning two different languages at the same time has it's pros and cons, but if you have a lot of spare time I would recommend learning a less strict language, like Python or Ruby.
For Python the official docs have a good tutorial: http://docs.python.org/3/tutorial/introduction.html
This Ruby tutorial is interactive and seems like a good one: http://rubymonk.com/
The current language I use for my current projects is Scala. It is purely object oriented and a very nice language. But it's complicated in a lot of ways so I wouldn't recommend it either as a beginniners language. In fact it's probably harder than Java, but in the end it makes more sense than Java. http://joelabrahamsson.com/entry/learning-scala
EDIT: When you have learned the basics of a language, I found making an IRC-bot a good excercise. It learns you string handling and requires you to solve some real world problems (like getting the title when someone posts an url).
It's not Java, but if you are unfamiliar with basic coding concepts (i.e. Classes, methods, logic/control structures, etc), I would recommend starting with the basics and try something fairly straightforward like RubyMonk, which runs in a browser and doesn't require you to install anything.
Don't worry too much about how "popular" a language is, as it depends highly on what aspect of coding you want to get into long term.
I would check out Gosu, a 2D library and DSL for rapidly developing any kind of 2D game in Ruby/C++. It's very mature (been continuously in dev. since 2001) and has built in 2D/3D GPU acceleration libraryies for Directx and OpenGL. The syntax is pretty much Ruby-like, high level commands and should be pretty easy to pick up.
It will be a lot easier to learn if you understand some basic code structures, types, and syntax. For that I would recommend taking a few hours/days and running through the entire Ruby Monk self-paced, browser-based Ruby lessons
Okay, I'm perusing the lesson. Did you successfully write a lambda
for the with_names
exercise higher on the page? If so, look at the [].each do |pair| ... end
block inside the with_names(fn)
function. That tells you how to fill in the each do |pair| ... end
block in the Array#transmogrify
method. You're already on the right track by using yield
instead of fn.call
.