Kang-Kyu Lee

Ruby + Rails codewriter

Page 4


Setup Ruby with Ubuntu

setup Ruby on Ubuntu 12.04 LTS with rbenv - I installed Ubuntu to my old laptop (Windows 7) with - wubi. And I did

open terminal = ctrl + alt + T

(and then connect to Wi-Fi )

install git

$ sudo apt-get update
$ sudo apt-get install git

https://github.com/sstephenson/rbenv#installation

https://github.com/sstephenson/ruby-build#readme

follow direction and install rbenv + ruby-build

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL 
$ type rbenv
"rbenv is a function"
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

install ruby - stable versions

  • Ruby 1.9.3-p545
  • Ruby 2.0.0-p451
  • Ruby 2.1.1
$ rbenv install 1.9.3-p545
$ rbenv install 2.0.0-p451
$ rbenv install 2.1.1
$ rbenv versions
$ rbenv global 2.0.0-p451
$
...

Continue reading →


HTTP, a stateless protocol

  1. The Protocol Every Web Developer Must Know - Part 1
  2. HTTP Made Really Easy

These two links are what I read on. From requests, server make it responses.

It’s a stateless, application-layer protocol for communicating between distributed systems.

There are “verbs” such as

  • GET
  • POST
  • PUT
  • DELETE

and “status codes”

  • 200 OK
  • 301
  • 404 Not Found
  • 500 Internal Server Error

Have a Request, three things

  • url (Link / Path / Route)
  • a verb
  • parameters

give a Response

  • status code
  • message body (payload)

check Request header. Response format. use “HTTP client” tool.

and use Chrome/webkit inspector.

Continue reading →


Terms: parameter, argument

if a method takes arguments, we say it accepts or expects those arguments.

The argument is the piece of code you actually put between the method’s parentheses when you call it, and the parameter is the name you put between the method’s parentheses when you define it.

def square(number)
    puts number**2
end

square(2) 

# number <= parameter
# 2 <= argument

It is always good to know the terms right, again from Codecademy.

View →


have a hash with a default value

Revisiting codecademy Ruby… it says:

If you have a hash with a default value, and you try to access a non-existent key, you get that default value.

irb(main):001:0> a = Hash.new
=> {}
irb(main):002:0> b = Hash.new(0)
=> {}
irb(main):003:0> a["john"]
=> nil
irb(main):004:0> b["john"]
=> 0
irb(main):005:0> a == b
=> true

This is great…

View →


start with Git

Steps to start Github.com

  1. open the terminal

  2. in a local directory, say

    git init
    

    as like

    ~/projects/first_repo $ git init
    

    (before this step, install “git” on your laptop)

  3. and then, say

    git remote add origin repo_url
    

    with the repo URL (before this, open a github.com account & get a repo)

  4. then it worked. after that, whenever edit something on the directory (when have something to commit) use

    git status git add . 
    git commit -m "description"
    
  5. and when say finally,

    git push
    

    then it asks login ID & password at github.com

View →


only one copy of symbol

irb(main):001:0> "string".object_id == "string".object_id
=> false
irb(main):002:0> :string.object_id == :string.object_id
=> true

The .object_id method gets the ID of an object—it’s how Ruby knows whether two objects are the exact same object.

irb(main):002:0> string = "string"
=> "string"
irb(main):003:0> string.object_id == "string".object_id
=> false
irb(main):004:0> string = :string
=> :string
irb(main):005:0> string.object_id == :string.object_id
=> true

View →


short circuit evaluation

Ruby doesn’t look at both expressions unless it has to; if it sees

false && true

it stops reading as soon as it sees && because it knows false && anything must be false.

View →


Setup Ruby with Macintosh

http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-mac-os-x/

when install rbenv:

echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

if (~/.bashrc) : ‘gem install rails’ not working. why?

when upgrade rubygems:

$ gem update --system
          # may need to be administrator or root

https://rubygems.org/pages/download

when install sublime_text

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

~/bin/subl seems not working. why?

View →