beanz Magazine

Ruby

Developed in 1993, Ruby is a highly flexible programming language used in many large scale online applications at Twitter, Kickstarter, and other companies.

The original creator of Ruby, Yukihiro Matsumoto of Japan, wanted to find a programmer friendly scripting language that was not difficult to learn or code with over time. Because he could not find such a language, he developed Ruby. The first release was announced on the Japanese ruby-talk list on December 21, 1995, almost three years after the language was announced on the same list.

Ruby was influenced by the best features and qualities of Perl, SmallTalk, Ada, and Lisp, among other languages. Bad experiences with these languages also influenced the design of Ruby. For example, in Perl there might be a number of ways to accomplish a task while Python has only one way. Ruby chose the Python model. As Matsumoto described in the Ruby Language FAQ:

“I was talking with my colleague about the possibility of an object-oriented scripting language. I knew Perl (Perl4, not Perl5), but I didn’t like it really, because it had the smell of a toy language (it still has). The object-oriented language seemed very promising.
I knew Python then. But I didn’t like it, because I didn’t think it was a true object-oriented language — OO features appeared to be add-on to the language. As a language maniac and OO fan for 15 years, I really wanted a genuine object-oriented, easy-to-use scripting language. I looked for but couldn’t find one. So I decided to make it.”

Ruby is a general purpose object oriented scripting language that is dynamic and reflective. Which is a long way to say the language is designed to spare programmers work required by other less flexible languages.

What Makes Ruby Special?

One interesting feature of Ruby is its reliance on the Principle of Least Astonishment or POLA. As noted in an article published earlier in this magazine, POLA tries to give software users what they expect to see when they expect to see it.

Perhaps the easiest way to describe POLA is to talk about common web page buttons. At the bottom of a web page form is a Submit button. Everyone who has filled out a form online expects to see at the bottom of the form a rectangle with the word “Submit” on top. Imagine if there was only a link that said “Submit”: that would confuse lots of people.

The Submit button creates the least astonishment for people who fill out a web page form. It’s expected. A link instead of a Submit button causes confusion, or the greatest astonishment.

With programming languages, POLA means the rules of programming are simple, obvious, and in all the right places. It involves efficiency, less code, and more power. POLA with programming languages also involves reflection, the ability for a programming language to interpret code in a dynamic way. For example, Ruby uses reflection to minimize how much hard coding of method names is required. When a script is run, Ruby figures out the best way to call different methods based on how the code is organized.

Ruby also has a few interesting features. For example, constants are always capitalized. And the @ symbol is used to define the scope of a variable, whether it is available only within a method or a class that contains the method. Perhaps the most programmer-friendly aspect of Ruby? You will never have to use semi-colons again in your code, or worry about them.

The name Ruby comes from a desire Matsumoto had to name the language after a jewel, like the Perl language. The choices were coral or ruby. Ruby was chosen in part because it was the birthstone of one of the early developers of the language.

How is Ruby Used?

Because Ruby is designed to be programmer friendly, the language is used in lots of places where people want to create software quickly that can be extended over time with minimal recoding. With Ruby on Rails (RoR), a web application framework, Ruby is most often used to create online applications like Twitter, Kickstarter, Basecamp, Shopify, and many other applications which need to be developed quickly and scale to lots of users over time. It’s a great language for software startups.

Here’s a code example from the Ruby website, to give you an idea how the language works:

# Output "I love Ruby"
say = "I love Ruby"
puts say

# Output "I *LOVE* RUBY"
say['love'] = "*love*"
puts say.upcase

# Output "I *love* Ruby"
# five times
5.times { puts say }

If you are familiar with Python and other languages, you’ll easily see puts does the same work as print() in other languages. And say.upcase would be the same as strtoupper($say) in PHP. Which is another thing to notice: the variable say doesn’t use a $ to visually indicate it is a variable.

Learn More

Ruby

https://www.ruby-lang.org
https://www.ruby-lang.org/en/documentation/
https://www.ruby-lang.org/en/documentation/quickstart/
https://www.ruby-lang.org/en/community/
http://rubycentral.org/
http://ruby-doc.com/docs/ProgrammingRuby/
http://en.wikipedia.org/wiki/Ruby_%28programming_language%29

Ruby from Other Languages

Describes differences between Ruby and C/C++, Java, Perl, PHP, and Python languages.
https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/

Try Ruby in Your Browser

http://tryruby.org/levels/1/challenges/0

The Ruby Language FAQ

http://ruby-doc.org/docs/ruby-doc-bundle/FAQ/FAQ.html

Comparison of Programming Languages

http://en.wikipedia.org/wiki/Comparison_of_programming_languages

Reflection

http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29

4 Reasons Why You Should Learn Ruby As Your First Programming Language

http://www.skilledup.com/articles/4-reasons-learn-ruby-first-programming-language/

What’s Special About Ruby?

http://astonj.com/tech/whats-special-about-ruby/

What makes Ruby an Elegant Language?

http://stackoverflow.com/questions/1812225/what-makes-ruby-an-elegant-language

What are the Benefits of Ruby on Rails? After Two Decades of Programming, I Use Rails

http://www.toptal.com/ruby-on-rails/after-two-decades-of-programming-i-use-rails

The Many Interpreters and Runtimes of the Ruby Programming Language

http://www.toptal.com/ruby/the-many-shades-of-the-ruby-programming-language

A Beginners Guide to Ruby

https://hackhands.com/beginners-guide-ruby/

Learn Ruby the Hard Way

Actually this online book is one of the easiest ways to learn Ruby in depth.
http://learnrubythehardway.org/book/
http://learnrubythehardway.org

Also In The June 2015 Issue

Automate the Boring Stuff with Python

This book helps average non-technical people free themselves from mundane computer tasks.

Solar Cockroaches, Water Rockets, and Pinhole Eyeglasses

Here are a few of the many fun summer projects at Instructables.com website.

Bitsbox: Monthly Coding Projects in the Mail

Every month the Bitsbox service delivers a colorful booklet full of fun coding projects for kids to do then share with friends and family.

Simple and Fun 3D Models to Print

Here are a number of simple and fun 3D models to print.

FUZE Computer Teaches Kids to Code

The FUZE computer is a 1980s computer design with the brain of a modern Raspberry Pi. It's ideal for teaching kids to code plus build electronics projects.

An Interview with Paul Chayka

Paul Chayka talks about Robotics And Beyond, an after school tech program that teaches coding, robotics, circuit design, and much more.

Teach Your Kids to Code

Learning Python is a fun way to spend time and learn programming together.

Kano Computers

The Kano computer is a Raspberry Pi computer with a spiffy installation process (and user manual) and a carefully thought out online experience.

Functions and Procedures

An introduction to programming functions and procedures using pen and paper instead of code. Includes lots of examples and exercises.

Ruby

Ruby is a highly flexible programming language used in many large scale online applications at Twitter, Kickstarter, and other companies.

June 2015 Learn More Links

Links from the bottom of all the June 2015 articles, collected in one place for you to print, share, or bookmark.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

June 2015 News Wire

News and project stories about kids, coding, computer science, and how we use technology in our daily lives.

Create Art with the Paper App + Mix

The Mix community lets you find and share artwork to create projects with free Paper software.