Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/carpark.rb
Overview
carpark.rb RubyTut
Created by Bryce Kerley on 2006-11-08. This code is public domain.
Subversion info: $Id: carpark.rb 177 2006-11-13 01:56:06Z bkerley $
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/carpark.rb', line 12 def method_missing(m, *a) s = m.to_s return super.method_missing(m, a) unless s =~ /c[ad]+r/ o = s[1..-2] return self[0].send("c#{o[0..-2]}r".to_sym) if o[-1..-1]=="a" return self[1..-1].send("c#{o[0..-2]}r".to_sym) if o[-1..-1]=="d" return "failed #{o}" end |
Instance Method Details
#car ⇒ Object
23 24 25 |
# File 'lib/carpark.rb', line 23 def car return self.first end |
#cdr ⇒ Object
27 28 29 |
# File 'lib/carpark.rb', line 27 def cdr return self[1..-1] end |