# How to learn ruby with ironslut method

I am going to propose a visual, easy, funny way to learn code. Why learning code has to be boring?

Ironslut it is based on: visual easy notes → fucking fun exercises. Using street dictionary.

If you don’t know anything about ruby, HTML, CSS or Javascript,… we are going to make an quick ruby review in just 2 minutes. After that, we will do 3 exercises in just other 3 minutes. Let’s fucking learn!

#### 1. Variables and Conversions

It sounds crappy, I know. But it is just this:

`a = 1 --> Integer (Fixnum)b = 2.4 --> Floatc = "yo bitch!" --> String`
`# a conversion to float  a = a.to_f  --> 1.0# b conversion to integer  b = b.to_i  --> 2# c conversions  c = c.to_s  --> "yo bitch!"  c = c.to_i  --> 0  c = c.to_f  --> 0.0`
What have you learned? There are numbers and strings in ruby. And if you transform “yo bitch!” to number, it will return zero.

#### 3. Arrays

`# Syntax: it is like a box of things: numbers, strings,... arr = [2, 5, 1, 3, 4] arr.size --> returns 5# Create an array (2 ways) arr = [] arr = Array.new# Add elements to array (3 ways) arr = [] arr << 1 --> way 1 arr.inyect(1, "bitch") --> way 2 arr[2] = true --> way 3 > [1, "bitch", true]# Obtain element from array arr = [1, "bitch", true] arr[0] --> returns 1 arr[1] --> returns "bitch" arr[2] --> returns true`
`# Convert String to Arraystr = "fuck"str.split('') --> returns ["f", "u", "c", "k"]`
`# Navigate through an array  arr = ["you", "are", "a", "shitty"]  arr.each do |a|    puts "resultado: #{a}"  end  > result: "you"    result: "are"    result: "a"    result: "shitty"`
`# Printing n times  str = "crap"  n = 3`
`  (1..3).each do |i|    puts "crap #{i}"  end`
`  > crap 1    crap 2    crap 3`
What have you learned? the array it is like a box: you can add and remove elements and navigate through them.

#### 2. Interactions

`a = 1b = "yo nigga"`
`puts a  --> returns 1puts "the value of a is #{a}" --> returns "the value of a is 1" print "yo nigga"c = gets.chomp --> ask value to user (string)d = gets.chomp.to_i --> it transforms to integer`
`# puts  --> jump the line# print --> not jump the line`
What have you learned? puts 1 jump the line and print “yo nigga” does not jump the line. Both returns values to the screen. And gets.chomp ask user for the value.

Just 3 easy definitions and now it is time to exercise yourself. And this is what we have to do:

1. Write a program that prints “Hey Bitches!” to the screen.

2. Write a program that asks the user for a number n and prints the sum of the numbers 1 to n.

3. Write a program that takes a list of 3 strings (words) an prints them, one per line, in a rectangular frame. For example the list [“fuck”, “that”, “shit”] gets printed as:

`* * * * * ** f u c k ** t h a t ** s h i t ** * * * * *`

And these are the results:

1. Write a program that prints “Hey Bitches!” to the screen.
`prints "Hey Bitches!"`

2. Write a program that asks the user for a number n and prints the sum of the numbers 1 to n.

`# Ask user for the number nprint "Hey nigga, I need a number"n = gets.chomp.to_i`
`# Navigate from 0 to n and sum the number to new variable ii = 0(1..n).each do |number|   i = i + number  end`
`print "result: " + i.to_s`

3. Write a program that takes a list of 3 strings (words) an prints them, one per line, in a rectangular frame. For example the list [“fuck”, “that”, “shit”] gets printed as:

`* * * * * ** f u c k ** t h a t ** s h i t ** * * * * *`

And this is the result of exercise 3:

`# Ask user for the 3 strings and convert to arrayprint "Hey nigga, first string"a1 = gets.chomp.split('')print "Hey nigga, second string"a2 = gets.chomp.split('')print "Hey nigga, third string"a3 = gets.chomp.split('')`
`# Creating result lines for each stringresult = [][a1, a2, a3].each do |arr|  str= "*"  arr.each do |c|     str = str + " " + c  end  str = str + " *"  result << strend`
`# Creating the starsmax_size = [a1.length, a2.length, a3.length].maxstars = "* "(1..max_size).each do |x|   stars = stars + "* "endstars = stars + "*"`
`puts starsputs result[0]puts result[1]puts result[2]puts stars`

Nice approach to ruby ha!

#### Where to keep learning?

If you want to keep learning ruby, HTML, CSS or Javascript,… just have to study the notes and make next exercises:

http://ironslut.codaffinity.com/index.html

• If you want to learn programming in one month, just ask us for a mentor.
• If you don’t want a fucking mentor, just learn by yourself with the website, and ask us any questions.
• We could teach you how to code and create your own portfolio, and teach you about how to find projects or how to find a job.

I wish you a fucking learning.

codaffinity.com

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.