background preloader

Great Blogs & Portals

Facebook Twitter

Practicing Ruby eZine

PLEAC-Ruby. Ruby’s Unary Operators and How to Define Their Functionality. In math, a unary operation is an operation with a single input. In Ruby, a unary operator is an operator which only takes a single 'argument' in the form of a receiver. For example, the - on -5 or ! On ! True. In contrast, a binary operator, such as in 2 + 3, deals with two arguments. Here, 2 and 3 (which become one receiver and one argument in a method call to +). Ruby only has a handful of unary operators, and while it's common to redefine binary operators like + or [] to give your objects some added syntactic sugar, unary operators are less commonly redefined. A Quick Example with -@ Let's ease into things with the - unary operator. Using the - unary operator on a string in irb: ruby-1.9.3-p0 :001 > -"this is a test" NoMethodError: undefined method `-@' for "this is a test":String The String class doesn't have unary - defined but irb gives us a clue on where to go.

Str = "This is my STRING! " Some Other Operators: +@, ~, ! Note: You cannot redefine ! Special Cases: & and * & and to_proc. Why's (Poignant) Guide to Ruby. Read This Paragraph At my local Barnes and Noble, there is a huge wall of Java books just waiting to tip over and crush me one day. And one day it will. At the rate things are going, one day that bookcase will be tall enough to crush us all. It might even loop the world several times, crushing previous editions of the same Java books over and over again. And This Paragraph Too This is just a small Ruby book. But Don’t Read This One! Why’s (Poignant) Guide to Ruby is released under the Attribution-ShareAlike License. Now Back to Your Regularly Scheduled Paragraph I’ll try not to feel utterly rejected if this book doesn’t capture your fancy.

Learning to Program A very basic, ground-level tutorial for the beginner to Ruby. Now, if you can’t seem to find the contents link on the left-hand side of the page, then here’s a link to the first page of the (Poignant) Guide. Welcome to the pirate radio of technical manuals. Ruby Programming/Reference/Objects/Enumerable. Enumerable[edit] Enumerator appears in Ruby as Enumerable::Enumerator in 1.8.x and (just) Enumerator in 1.9.x. There are several different ways in which an Enumerator can be used: As a proxy for “each”As a source of values from a blockAs an external iterator 1. As a proxy for “each”[edit] This is the first way of using Enumerator, introduced in ruby 1.8. It solves the following problem: Enumerable methods like #map and #select call #each on your object, but what if you want to iterate using some other method such as #each_byte or #each_with_index?

An Enumerator is a simple proxy object which takes a call to #each and redirects it to a different method on the underlying object. require 'enumerator' # needed in ruby <= 1.8.6 only src = "hello" puts src.enum_for(:each_byte).map { |b| "%02x" % b }.join(" ") The call to ‘enum_for’ (or equivalently ‘to_enum’) creates the Enumerator proxy. Newsrc = Enumerable::Enumerator.new(src, :each_byte) puts newsrc.map { |b| "%02x" % b }.join(" ") 2. 3. Zen and the Art of Programming. Ruby Tutorial. Ruby is a scripting language designed by Yukihiro Matsumoto, also known as Matz. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding on Ruby.

This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to Ruby Scripting languages. Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program and what is a computer programming language. For most of the examples given in this tutorial, you will find Try it option, so just make use of it and enjoy your learning. Try following example using Try it option available at the top right corner of the below sample code box: #! 1 - Ruby Quick Reference Guide A quick Ruby reference guide for Ruby Programmers. Ruby Quick Reference Guide 2 - Ruby Built-In Useful Functions Ruby Built-In Useful Functions.

Ruby-Doc.org: Documenting the Ruby Language. Front page - APIdock. The Bastards Book of Ruby.