- RSpec: write rspec first, then implement code
- Organize project: top/ ./bin ./lib/top ./test
- Use setup.rb for distributing project
- RubyGems: open rdoc for library: open $gemdoc/builder/.../rdoc/index.html
- Encoding: # encoding: utf-8/ over 7bit characters assume the source file encoding
- Input Output Encoding: File.open("filename", "r:iso-8859-1:utf-8:")
- irb: load "your ruby file with classes or methods" : you use the classes in irb session. also can edit the file after loaded.
- irb: use tab completion alot
- irb: use irb in irb to make a subsession: jobs, fg 0, kill 1
- irb: use irb with specific class: irb "wombat"
- Constant: Constant can define from the outside.
- Module: module_function: makes instance method module method also.
- Exception: rescue modifier: ["1","2.3",/pattern/].map {|v| Integer(v) rescue Float(v) rescue String(v)}
- Exception: retry can be used in rescue clause.
- methods(false): just show methods in the object; exclude superclasses'
- Duck typing: if you need check types: use obj#respond_to?
- type conversion: method coersion: 1.coerce(2.3) -> [2.3,1.0];define coerce method in your class correctly, you get arithmetic func with numbers.
- metaprogramming:module:ruby makes anonymous super class for a class, in which module is mixed in.
- metaprogramming:extend: when use extend to a obj, the module is included to an anonymous class of the obj.
- metaprogramming:extend: when use extend in a class, the module method become its class method. that means extend makes singleton method
Thursday, August 28, 2008
Programming Ruby 3 - New topics
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment