Содержание
- 2. Anton Shemerey https://github.com/shemerey https://twitter.com/shemerey https://www.facebook.com/shemerey https://www.linkedin.com/in/shemerey [email protected] etc.
- 3. Code style https://github.com/bbatsov/ruby-style-guide https://github.com/bbatsov/rails-style-guide Use two spaces per tab! explicit “return” - is evil
- 4. OOP - Everything is object, not quite but still...
- 5. “hello” - this is object too 1 2 a = "hello" # instance 3 b =
- 6. 42 - this is object too 42.instance_variables # => [] 42.instance_variable_set(:@hello, 'world') 42.instance_variables # => [:@hello]
- 7. true - this is object too true.instance_variables # => [] true.instance_variable_set(:@false, true) true.instance_variables # => [:@false
- 8. Class 3 class Point 4 def initialize(x, y) 5 @x, @y = x, y 6 end
- 9. attribute reader/writer 1 class Point 2 def initialize(x) 3 @x = x 4 end 5 6
- 10. 1 module ReadWrite 2 def rw(*params) # params = [:x, :y] 3 params.each do |attr| 4
- 11. Class / Module Module.ancestors # => [Module, Object, Kernel, BasicObject] Class.ancestors # => [Class, Module, Object,
- 12. class A; end new inheritance include class A - computer says no extend class A -
- 13. module B; end new - computer says no inheritance - computer says no include B extend
- 14. include/extend 1 module M 2 def inst_method 3 "instance" 4 end 5 end 6 7 8
- 15. 1 module M 2 def self.included(base) 3 base.extend(ClassMethods) 4 end 5 6 # -- instance methods
- 16. Classes and Objects More information: http://bit.ly/YZBfmp
- 17. Ruby Blocks 1 %w[first second third].each do |item| 2 item.capitalize 3 end 4 5 %w[first second
- 18. Yield
- 19. 1 require "ostruct" 2 Point = Struct.new(:x, :y) 3 4 class PointList 5 def initialize 6
- 20. Enumerable
- 21. 1 require "ostruct" 2 3 Point = Struct.new(:x, :y) do 4 def distance 5 Math.sqrt(x**2 +
- 22. Comparable 1, 0, -1
- 23. 1 require "ostruct" 2 3 Point = Struct.new(:x, :y) do 4 include Comparable 5 6 def
- 24. Mad Ruby
- 25. #to_proc (&) 1 class Symbol 2 def to_proc 3 Proc.new { |*args| args.shift.__send__(self, *args) } 4
- 26. Advanced Examples 1 File.open('nginx.log', 'r') do |file| 2 while line = file.gets 3 puts line 4
- 28. Скачать презентацию