Difference between revisions of "Ruby on Rails"

From Wikicliki
Jump to: navigation, search
(the command line)
(Naming Conventions)
Line 68: Line 68:
 
* constants are in ALL_CAPS
 
* constants are in ALL_CAPS
  
 +
== Variables ==
 +
* var  # local variable (or method call)
 +
* @var  # instance variable
 +
* @@var # class variable
 +
* $var  # global variable
 +
* VAR  # constant
  
 
== Playing with IRB ==
 
== Playing with IRB ==

Revision as of 06:36, 13 May 2012

ruby is a language, rails is a framework object-oriented, general purpose

rails philosophy

  • opinionated
  • convention over configuration
  • don't repeat yourself
  • test driven
  • minimal code - maximal effect

the tools

  • rails
  • rake - like maeke for ruby (an easy way to run tasks)
  • git - source code control
  • database - SQlite
  • heroku - fre rails hosting

the command line

  • ls - list
  • cd - go to directory (use cd ~ to go backwards)
  • pwd - "print working directory"
  • echo - repeats it (used to echo out $PATH)
  • touch - creates a file
  • cat - tells info
  • mv - move
  • cp - copy
  • rm - remove (DELETE FOREVER)
  • man <command> - tells you more (press q to get out) (man - manual)
  • mkdir - make directory
  • rmdir - remove directory
  • mdfind - find file (find via spotlight)

Example:

  • to rename a file frm file1 to file2 and move file to a different dir: mv file1 dir1/file2
  • Current directory: . ("dot")
  • Parent directory: .. ("dot dot")
  • Home directory: ~ ("tilde")
  • Command-K to clear screen


  • cat <filename> - prints the file
  • ruby <filename> - runs the file
  • git status - check git (versioning) status
  • git add . - prepare to commit everything all files
  • git add <filename> - prepare to commit specific file
  • git commit -m - commit that file
  • git help <function name>
1.9.3p194 :024 > def test (name="debbie", country="singapore")
1.9.3p194 :025?>   puts "My name is #{name}"
1.9.3p194 :026?>   puts "My country is #{country}"
1.9.3p194 :027?>   end
 => nil 
1.9.3p194 :028 > test
My name is debbie
My country is singapore
 => nil 
1.9.3p194 :029 > 

Naming Conventions

  • methods and variables are in snake_case
  • classes and modules are in CamelCase
  • constants are in ALL_CAPS

Variables

  • var # local variable (or method call)
  • @var # instance variable
  • @@var # class variable
  • $var # global variable
  • VAR # constant

Playing with IRB

system('cls')

See Also