- Remember:
- **Variables **and Assignment
- **Basic **Data and Datatypes
- **Data **Structures
- Blocks, **Procs **and Lambdas
- Cucumber
Still in progress…
In my opinion these are some things that feel would actually be beneficial, in contrast to / on top of the suggested group programming exercises.. Here are some topics to cover in:
Analogy: Programs are like magic boxes..
Think of RUBY
being an expression-oriented language, like most scripting languages, produces values upon the execution of every line..
The simplicity and brevity of the language can be encapsulated as follows.
Consider the snippet:
def five
5
end
five
output » 5 => nil
print five()
output » 5 => nil
Remember:
last line of a method (or function) is returned_ **by **_default
and the nil above is what is returned from the print method
irb
once Ruby is installed on your machine, bust out IRB (Interactive Ruby Shell) and have fun
ie: *WinKey+R > cmd > irb*
Things you should know..
**Variables **and Assignment
- Almost anything is a variable (anything other than Constants, symbols and numbers)
just say * a = something*
- Parallel Assignment
```ruby
- one,two,three = 1,2,3 ```
-
Constants
-
Variadic Methods and the * operator
- basically bulk arguments passing
**Basic **Data and Datatypes
- Booleans
- and, &&
-
or, - TRUEs
- FALSEs
- strings
-
‘these’ and “these”
- concat ‘+’ and other prebuilt methods for string manipulation like
- upcase
- downcase
- capitalize
- concat ‘+’ and other prebuilt methods for string manipulation like
-
etc..
6. printing
1. print
2. puts
3. p
4. warn
etc..
7. String Interpolation ```ruby a=1+2 or a = nil
“1+2= #{ a | 1+2 }” |
1+2=3 ```
-
numbers
-
ints and floats
- all arithmetic operators:
-
+,-,*,/,raised to the power **,<,>, etc..
-
Enumerables
-
each
-
count
-
select
-
map
-
collect,
-
etc…
* trick -- [a,b].map(&:upcase)
- symbols
:i_am_a_symbol :symbols_begin_with_a_colon_and_are_one_word
- nil
nil type
**Data **Structures
- array [ ] ```ruby a=[‘things’, “like” , :this ,123]
a[2]
>> "like"
2. hash { }
```ruby
h={:one => "this" , or: :symbol, also: 12 }
h[:also] = 12
h[:does_not_exist]=nil
- range (iterables)
1..10 # one to ten 1...10 # one to nine
Blocks, **Procs **and Lambdas
-
do..end
-
same as {
} -
Blocks and Yields
-
- if..else..end
if 1<3
print ‘lesser than’
elsif 1==3
puts “equal”
else
p “greater than”
end
- also one liners
print “yes” if 1<3
- while..end
i=-5
while i<=5
p i; i+=1
end
- case
a=”something”
a=case a
when “b” then “b”
when nil
“nil”
else
“this is default”
end
“this is default”
- proc
add = -> a,b {a+b}
add[1,3] or add.call(1,3)
4
More Advanced Topics:
- Classes
- Modules
- Monkey Patching
- Projects
- Gems (libraries)
Cucumber
and Gherkins
Before I write more things here for the More Advanced Topics,
lemme know what you think about this so far
like whether i should elaborate more or just list out the stuff to cover..