Programming Ruby 1.9

David Thomas

Mentioned 11

A tutorial and reference to the object-oriented programming language for beginning to experienced programmers, updated for version 1.9, describes the language's structure, syntax, and operation, and explains how to build applications.

More on Amazon.com

Mentioned in questions and answers.

I am new to the language and I need to know what are the top things that are absolutely necessary to know in order to make a fully functional website or web app using the Ruby programming language?

Mainly Ruby on Rails with Rake and other tools that mainly use Rake.

Update: I know many other languages like C++, Java, PHP, Perl, etc, etc ....

Update 2: This is great ... keep 'em coming!

v 1.9 is very very different than v 1.8. Code built for 1.8 is NOT guaranteed to work in 1.9, and vice versa.

I had a whole bunch of code that worked in v 1.8 and didn't in v 1.9, and then had to deal with two machines that had different versions on each. Not fun.

Make sure to choose a version (probably the latest, but be wary that a lot of sample code in blogs on the web is 1.87, as is the second edition of Programming Ruby. There's since been released a third edition of Programming Ruby that covers 1.9, and that's the one you want.

Also, if you're at all like me, you'll be singing one of three songs while programming it:

I do not know Ruby and I am interested to learn MacRuby.
What would you recommend as your best resource (books, blogs, sites)?
Found:http://www.macruby.org/

More info her from rubyconf.org Macruby talk

If you don't know ruby then these 3 books will bring you up to speed relatively quickly. The nice thing is that you can use "Design Patterns in Ruby" as your primary text and the other 2 as reference texts (although you should definitely read "The Ruby Programming Language" all the way through at some point):

  1. The Ruby Programming Language
  2. The Pickaxe Book
  3. Design Patterns in Ruby

I'm coming from C#, and recently I started to write some Ruby on Rails applications.

My biggest problem with it is the documentation because I find it extremly difficult to use. For example, finding out how to call generator from my controller took me about 2 hours and then 15 minutes after that I found Rails::Generators.invoke method to figure out what arguments should I pass to this function.

Maybe I use the documentation the wrong way; First I take a wild guess and search in the Netbeans code completion, which is rarely helpful, then I search in Google, then go with the API.

Can some experienced Rails programmer give me some advice?

If you're new to rails I recommend you read a book before you dive into the API documentation.

Here are two recommendations:

After you've worked your way through those books, you'll have an idea of how Rails is designed and where to look for stuff.

Both books are great reference books. If you want to access the Rails and Ruby API's online, make sure to checkout RailsApi.com

Suggestion of a new beginners book for Ruby?

I've come across conversions of the form Array(value), String(value), and Integer(value) on occasion. It appears to me that these are just syntactic sugar for a call to the corresponding value.to_a, value.to_s, or value.to_i methods.

So I'm wondering:

  • Where/how are these are defined? I can't find them in Object, Module, Class, etc
  • Are there any common scenarios for which it's preferable to use these rather than the corresponding/underlying to_X method?
  • Could these be used in type-generic coercion? That is, can I do something along the lines of

    [Integer, String, Array].each {|klass| klass.do_generic_coercion(foo) }
    

? (...and no, I don't really want to do that; I know the type I want out, but I'm looking to avoid the case statement.)

They are Defined in Ruby Kernel Module, like:

Array(), Complex(), Float(), Integer(), Rational(), Stirng(), etc.

I found those method references in Dave Thomas's Pickaxe book "Progamming Ruby 1.9", page 555.

For example: Array(arg) will convert arg as an Array, following are copied from the book: "Returns arg as an Array. First tries to call rg.to_ary, then arg.to_a. If both fail, creates a single element array containing arg( or an empty array if arg is nil)." ex.

 Array(1..5)   # => [1, 2, 3, 4, 5] 

Possible Duplicate:
What is the best way to learn Ruby?

There's tutorials on Rails but it's hard to find good on-line tutorials for Ruby.

What's your favorite one?

I’m going to make an advertising system from scratch and put it inside of my Ruby on Rails Web Application. What books do you recommend and subjects (Algorithms, SQL?) should I learn in order to make this happen, where does one start?

I want the system to take User Data and when businesses advertise, the Users will get recommended Ads based on their likes, dislikes and other data. The advertising will take place only in my web application and on my website. I believe I am looking to do something similar to Facebook Ad System (images) and Google Ad Words, how did they do it?

Thank you.

P.S. I have little experience in Rails, Ruby language,Computer Science and programming in general but i am learning fast and building my application easily.

Ilya Grigorik did an awesome writeup with lots of code samples on this subject. See http://www.igvita.com/2007/01/15/svd-recommendation-system-in-ruby/

If you mean books on Ruby and Rails, I can recommend:

Programming Ruby (AKA "The Pickaxe")

Agile Web Development with Rails

Those were the starting points of my Ruby career.

I'm currently writing my bachelor thesis about recommender systems with location based social networks. For the basics of recommender systems have a look at these books which helped me a lot: http://www.amazon.de/Recommender-Systems-Introduction-Dietmar-Jannach/dp/0521493366/ref=sr_1_1?ie=UTF8&qid=1300796937&sr=8-1

http://www.amazon.de/Recommender-Systems-Handbook-Paul-Kantor/dp/0387858199/ref=sr_1_3?ie=UTF8&qid=1300796937&sr=8-3

and if you speak german, this book gives a good survey: http://www.amazon.de/Empfehlungssysteme-Grundlagen-Konzepte-Andr%C3%A9-Klahold/dp/3834805688/ref=sr_1_2?ie=UTF8&qid=1300796937&sr=8-2

I am a non-coder and am very good at HTML. I am going to self-teach myself Ruby & Ruby on Rails because I hear it's a good skill to have but especially because it may be an easy first language to learn with my HTML background.

I would like to create my webpage, which will catalog my photographs, using Ruby on Rails. For a non-coder-HTML-user like myself, which would be a smoother transition:

1) Ruby before RoR

OR

2) Learn both at the same time

Thanks!

My first instinct is to say learn Ruby first, without doubt. I think any kind of framework is difficult to learn if you don't know 1) the language it uses, or worse 2) any programming language or programming language idioms/grammar/structures/etc.

But reading the comments in this thread, perhaps it's worth trying to learn RoR and Ruby at the same time. If it's too confusing, then pivot and focus on just learning the language first, and RoR later.

Regarding learning the language, while there are lots of Ruby blogs and sites, I think you can learn a language must faster if you work through a single good book first. Why's guide mentioned above is good and fun for experiened programmers, but needs to be supplemented by a real book for someone new to programming.

Good luck!

Could someone be kind enough to point me to a comprehensive manual (preferably a book) that would give me basic, step-by-step instructions to setting up and using ruby in a windows environment?

I'm a complete noob at Ruby, gems and Rails. Is it possible for me to get all-inclusive ground-up instructions on how to make web apps with Ruby in Windows?

So far I've read that rubyInstaller and Bash are a good way to use ruby in Windows; so inclusion of these tools would be a much appreciated bonus!

My biggest difficulty so far is simply getting bash set up so I can install gems and start coding apps against them (again I'm a complete noob!)

Also, what text editor/IDE for windows would be best for me to code in?

I would love an A-Z guide to installing Ruby/gems and making a Ruby-on-Rails app.

Thanks all!

Well, personally I would suggest you to develop Ruby on Rails applications on a Mac or Linux machine. But if you really want it on Windows, there's a one-click installer for Ruby.

http://rubyinstaller.org/

After installing it, you can install gems through the command prompt that comes with the installation. If however, you want a quick start with Ruby on Rails, I suggest you try out rails installer.

http://railsinstaller.org/

There are a lot of good beginner books for Ruby:

Learn to Program

  • A very nice and well-written tutorial on programming with Ruby. This book is for those who want a refresher on programming and want a nice introduction to the basic features of Ruby.

Programming with Ruby

  • Also called the PickAxe book, this book provides a complete guide and reference for Ruby.

And for Rails:

Ruby on Rails 3 Tutorial

  • A perfect step by step tutorial and intro to test-driven development (TDD) using Ruby on Rails. It also covers useful tools such as GIT (version control system) and deployment using Heroku.

Agile Web Development with Rails

  • This book guides you through a Rails project and examines Ruby on Rails in depth.

As for the text editor, I wouldn't recommend heavy or expensive IDE's, especially when you're just starting out. I would suggest you try out notepad++ which is free and lightweight, or you can try sublime text 2, which has a free evaluation copy, it's a very nice editor and looks like TextMate for Mac.

For example a file in active_support/core_ext/exception.rb

it started with:

module ActiveSupport
  if RUBY_VERSION >= '1.9'
    FrozenObjectError = RuntimeError
  else
    FrozenObjectError = TypeError
  end
end

Then continued with class Exception code

what does it mean? What do you use FrozenObjectError, RuntimeError, and TypeError objects for? How do I know where they are initialized? why do we need these lines of code?

Could you recommend me a good book to learn about this, please?

Thanks

Yes -- every line in Ruby is within an object, even the global scope. For your example, the 'error' for violating a Frozen Object is set based on what version is being run. In 1.9 it's a runtime exception whereas prior is a type error (this has to do with changes introduced in 1.9). This makes the exception as descriptive as possible.

Programming Ruby is very elegant at explaining the language:

Programming Ruby

Possible Duplicate:
What does “+=” (plus equals) mean?

What is the point of sum += square below? What does it mean?

sum = 0
[1, 2, 3, 4].each do |value|
  square = value * value
  sum += square
end
puts sum

I suggest you read up "Pragmatic Programmer's Guide to Ruby". Very nice explanation of Ruby concepts for beginners.