File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed
Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,14 @@ require 'rspec/core/rake_task'
55RSpec ::Core ::RakeTask . new ( :spec )
66
77task :default => :spec
8+
9+ task :console do
10+ require 'irb'
11+ require 'irb/completion'
12+
13+ require 'pry'
14+ require 'arbre'
15+
16+ ARGV . clear
17+ IRB . start
18+ end
Original file line number Diff line number Diff line change 11require 'arbre/element/builder_methods'
2+ require 'arbre/element/proxy'
23require 'arbre/element_collection'
34
45module Arbre
@@ -147,11 +148,11 @@ def +(element)
147148 else
148149 element = Arbre ::HTML ::TextNode . from_string ( element )
149150 end
150- ElementCollection . new ( [ self ] ) + element
151+ to_ary + element
151152 end
152153
153154 def to_ary
154- ElementCollection . new [ self ]
155+ ElementCollection . new [ Proxy . new ( self ) ]
155156 end
156157 alias_method :to_a , :to_ary
157158
Original file line number Diff line number Diff line change 1+ module Arbre
2+ class Element
3+ class Proxy < BasicObject
4+ undef_method :==
5+ undef_method :equal?
6+
7+ def initialize ( element )
8+ @element = element
9+ end
10+
11+ def respond_to? ( method , include_all = false )
12+ if method . to_s == 'to_ary'
13+ false
14+ else
15+ super || @element . respond_to? ( method , include_all )
16+ end
17+ end
18+
19+ def method_missing ( method , *args , &block )
20+ if method . to_s == 'to_ary'
21+ super
22+ else
23+ @element . __send__ method , *args , &block
24+ end
25+ end
26+ end
27+ end
28+ end
Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ def helper_method
6565
6666 end
6767
68+ it "to_a.flatten should not infinitely recurse" do
69+ Timeout . timeout ( 1 ) do
70+ element . to_a . flatten
71+ end
72+ end
73+
6874 describe "adding a child" do
6975
7076 let ( :child ) { Arbre ::Element . new }
You can’t perform that action at this time.
0 commit comments