Carlos Contreiras
I'm not the droid you're looking for. Move along, move along.
Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework.
High-level: meaning reading and writing Ruby is really easy—it looks a lot like regular English.
Read this in loud voice:
5.times { print "Apprentice!" }
exit unless "restaurant".include? "aura"
['toast', 'cheese', 'wine'].each { |food| print( food.capitalize ) }
Interpreted: meaning you don't need a compiler to write and run Ruby.
Object-oriented: meaning it allows users to manipulate data structures called objects in order to build and execute programs. All you need to know (for now) is that (almost) everything in Ruby is an object.
Easy to use: Ruby was designed by Yukihiro Matsumoto (often just called "Matz") in 1995. Matz set out to design a language that emphasized human needs over those of the computer, which is why Ruby is so easy to pick up.
Yukihiro Matsumoto a.k.a. Matz14 April 1965, Japan
string = "This is a string"
fixnum = 1
float = 1.0
regex = /d+/
array = Array.new
array[0] = 'element 1'
array[1] = 'element 2'
hash = Hash.new
hash[:key_a] = 1
hash[:key_b] = 2
class Badgers
attr_accessor :count
def initialize
@count = 1
end
def count_badgers
puts 'Counting badgers...'
(1..@count).each do |n|
if n % 5 == 0
puts "Mushroom mushroom!"
else
puts "#{n} Badger"
end
end
end
end
b = Badgers.new
puts "Current number of badgers: #{b.count}"
b.count_badgers
puts
b.count = 10
puts "Current number of badgers: #{b.count}"
b.count_badgers
require 'awesome_print'
ap('This is a string'.reverse)
ap(1.odd?)
ap(1.25.denominator)
ap(/A\d+/.match 'A01164096')
ap([1, 2, 3, 4, 5].shuffle)
ap({key_a: 1, key_b: 2}.merge({key_b: 2.5, key_c: 3}))
Return an array containing the numbers from 1 to N, where N is the parametered value. N will never be less than 1.
Replace certain values however if any of the following conditions are met:
15 mins ⏲
By Carlos Contreiras