How can this C and PHP programmer learn Ruby and Rails?

Posted by Winston on Stack Overflow See other posts from Stack Overflow or by Winston
Published on 2010-03-11T08:25:38Z Indexed on 2010/03/11 17:44 UTC
Read the original article Hit count: 445

Filed under:
|
|
|

I came from a C, php and bash background, it was easy to learn because they all have the same C structure, which I can associate with what I already know.

Then 2 years ago I learned Python and I learned it quite well, Python is easier for me to learn than Ruby. Then since last year, I was trying to learn Ruby, then Rails, and I admit, until now I still couldn't get it, the irony is that those are branded as easy to learn, but for a seasoned programmer like me, I just couldn't associate it with what I learned before, I have 2 books on both Ruby and Rails, and when I'm reading it nothing is absorbed into my mind, and I'm close to giving up...

In ruby, I'm having a hard time grasping the concepts of blocks, and why there's @variables that can be accessed by other functions, and what does $variable and :variable do? And in Rails, why there's function like this_is_another_function_that_do_this, so thus ruby, is it just a naming convention or it's auto-generated with thisvariable _can_do_this_function. I'm still puzzled that where all those magic concepts and things came from? And now, 1 year of trying and absorbing, but still no progress...

Edit: To summarize:

  1. How can I learn about blocks, and how can it be related to concepts from PHP/C?
  2. Variables, what does does it mean when a variable is prefixed with:
    • @
    • $
    • :
  3. "Magic concepts", suchs as rails declarations of Records, what happens behind the scenes when I write has_one X

OK so, bear with me with my confusion, at least I'm honest with myself, and it's over a year now since I first trying to learn ruby, and I'm not getting younger..

so

I learned this in Bash/C/PHP

solve_problem($problem)
{
  if [ -e $problem == "trivial" ];
    then
      write_solution();
    else
      breakdown_problem_into_N_subproblems(\;
      define_relationship_between_subproblems;
      for i in $( command $each_subproblem );
        do
          solve_problem $i
        done
  fi
}

write_solution(problem) {
  some_solution=$(command <parameters> "input" | command);
  command | command $some_solution > output_solved_problem_to_file
}

breakdown_problem_into_N_subproblems($problems) {
  for i in $problems;
    do
      command $i | command > i_can_output_a_file_right_away
    done
}

define_relationship_between_subproblems($problems) {
  if [ -e $problem == "relationship" ];
    then
      relationship=$(command; command | command; command;)
    elsif [ -e $problem == "another_relationship" ];  
      relationship=$(command; command | command; command;)
  fi
}


In C/PHP is something like this

solve_problem(problem)
{
  if (problem == trivial) write_solution;
    else {
      breakdown_problem_into_N_subproblems;
      define_relationship_between_subproblems;
      for (each_subproblem) solve_problems(subproblem);
    }
}

And now, I just couldn't connect the dots with Ruby, |b|{ blocks }, using @variables, :variables, and variables_with_this_things..

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rails