ruby programming language(ch1-2)
Pre-study
rvm
If you need to separate configurations & gems for each ruby project individually, rvm is a good tool.
install check:
type -t rvmgivesfunction
usage notes:
rvm install ruby <version>rvm use <version> --defaultto set defaultrubyto uservm gemset use <group>and thengem install <gem>to install gem to thatgroup- gems installed to
globalare inheritable
- gems installed to
some tips:
- make sure your term enable login-shell
- source rvm at last as possible to avoid warning:
...path/to/ruby-bin not at first place in PATH...
pry
Interactive tool like bpython, i use pry --simple-prompt for convenient like noob test, etc.
ri
Ruby manual, e.g: ri Array, ri Array.sort, ri Hash#each, ri Math::sqrt.
Ch2
comments
|
|
|
|
- there’s no
/* */like comment. #is prior to=begin(end)
some symbol in identifiers
prefix/suffix:
$: global var@: class instance var@@: class varxx?: boolean-valued methodxx!: in-place methodxx=: method invoked by assignment
reserved word:
__LINE____ENCODING____FILE____END__: after goes the data, you can refer these data byDATA
spaces
one line is implicitly closed if it’s a complete expression, check:
|
|
|
|
after ruby1.9, newline start with . implicitly considered as continuel line, like chain-invoke:
|
|
ruby has grammar candy for method invoke, care the trap:
|
|
use ruby -w to check ambiguous warning.