El Code Snippet

Take and Use ... It's cool!

Ruby: Introduction

In Ruby, everything is an object!

A string is an object that you can call methods on without doing any other types of conversion. Arrays are also objects that you can attach methods to. Variables do not need to be declared ... you just put them on their own line, assign a value to them and the Ruby interpreter will know it's type.

Let's take a look at a couple of examples.

Figure 1

In this example, variables are assigned values. These variables are objects that you can use methods on.

        # everything in Ruby is an object
        
        s = "this is a string ..."
        puts s.length
        # 20 characters
        
        arr = [5,3,2]
        puts arr.length
        # 3 elements
        
        numbers = (4...12).to_a
        puts "#{numbers}"
        puts numbers.length
            

Have a go at hacking the code yourself: https://repl.it/IiGu