Day 33, Sinatra

Magic!!!!!!!!

That is what I am thinking all the time. I thought Ruby itself has enough magic, I was so wrong! When I say magic, I don’t mean anything negative. Please refer to this quotes – “Any sufficiently advanced technology is indistinguishable from magic.”

ActiveRecord:
– ORM
– generates many methods for you, such as model.findall_by_column_name
– amazing feature set. Used as a model for many other ORMs
– many Ruby frameworks use ActiveRecord

Sinatra:
– lightweight compared to Rails; JavaScript equivalent would be Express(?)
– used for a CRUD application with medium level complexity
– Rails would probably be a better choice for more complicated applications with a lot of user interactions and page by page navigations
– not sure about which site has the largest scale Sinatra App

Advertisements
Standard

Day 30, the master says

The master says ” just like a feather, your code is floating in the air. ”

This is from the RubyMonk and we were having a blast going through it. Way way better than the CodeSchool Ruby Intro. When I was going through the CodeSchool Ruby Intro, I was like, “why people love Ruby again?”. When I was going through RubyMonk, now I knows why. Plus, the master has some really cool quotes there.

Some cool functions that I liked when I was going through this Ruby intro sprint: [].map, [].find, [].find_all, [].inject, {}.to_str (makes obj string-like). When I was using Ruby, I kept thinking that Matz must have spent thousands of hours thinking about all those functions. It is day and night compared to JavaScript and I am not sure one way is better than the other.

Lambda vs. Proc vs. Block

Note: just trying to be mostly right here. Totally needs to read more on this.

Blocks are like Procs without visible name. Blocks can be converted to Procs easily.

Lambda errors out with the wrong number of arguments; one of them has power to return differently(?)

##lambda
f1 = lambda do |args|
  puts args
end
f1.call 'this is aha'

##Proc
f1 = Proc.new do |args|
  puts args
end
f1.call 'this is aha'

##Block, not sure
['this is aha'].each do |args|
  puts args
end

JavaScript

var f1 = function(args){
  console.log(args);
};

f1.call(this, 'this is aha');

They are very tricky when used as callbacks

Case 1:

def f1
  yield('passing args')
end

f1 do |args|
  puts args
end

Case 2:

def f1
  yield('passing args')
end

callback = lambda do |args|
  puts args
end

f1(&callback)

Case 3:

def f1(&cb)
  cb.call('passing args')
end

f1 do |args|
  puts args
end

Case 4:

def f1(&cb)
  cb.call('passing args')
end
callback = lambda do |args|
 puts args
end

f1(&callback)

The master says: yo, time to go to bed.

Standard