Class: JQuery::Object
- Inherits:
-
Object
- Object
- JQuery::Object
- Defined in:
- lib/jquery.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#label ⇒ Object
Returns the value of attribute label.
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
Instance Method Summary collapse
-
#initialize(label, *args) ⇒ Object
constructor
A new instance of Object.
- #method_missing(method, *args) ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(label, *args) ⇒ Object
Returns a new instance of Object.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jquery.rb', line 14 def initialize(label, *args) @label = label.to_s @args = args.map do |arg| case arg when String JSString.new(arg) when Numeric JSNumeric.new(arg) when Symbol JSVar.new(arg) when Array, Hash JSStruct.new(arg) when Proc JSFunction.new(arg) else raise ArgumentError.new("#{arg.class} is not supported") end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/jquery.rb', line 57 def method_missing(method, *args) next_obj = self.class.new(method, *args) self.next = next_obj next_obj.prev = self next_obj end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
12 13 14 |
# File 'lib/jquery.rb', line 12 def args @args end |
#label ⇒ Object
Returns the value of attribute label.
12 13 14 |
# File 'lib/jquery.rb', line 12 def label @label end |
#next ⇒ Object
Returns the value of attribute next.
12 13 14 |
# File 'lib/jquery.rb', line 12 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
12 13 14 |
# File 'lib/jquery.rb', line 12 def prev @prev end |
Instance Method Details
#to_s ⇒ Object Also known as: to_str
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jquery.rb', line 34 def to_s current = self chain = [current] while current.prev current = current.prev chain.unshift(current) end result = [] chain.map do |obj| expr = '' expr << "#{obj.label}(" expr << obj.args.map { |arg| arg.to_s }.join(',') expr << ')' result << expr end result.join('.') end |