Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Output multi-lined blocks using do and end, single lined blocks using…

… curly brackets
  • Loading branch information...
commit 9ea44a9b1fee40d840d16acd566ef49530ac75a1 1 parent c1ae6af
@radar radar authored
Showing with 26 additions and 2 deletions.
  1. +11 −1 code.rb
  2. +10 −0 fixtures/block.rb
  3. +5 −1 processor.rb
View
12 code.rb
@@ -160,7 +160,7 @@ def process
end
def parse
- @sexp ||= self.class.ruby2sexp(self['code'], self['url'])
+ self.class.ruby2sexp(self['code'], self['url'])
end
# delegate pretty printing to sexp
@@ -271,6 +271,16 @@ def self.from_test_fixture(name)
code.reconstruct_code.should == ">> class class_inheritance\nclass Klass < Main\nend"
end
+ it "outputs curly brackets for one lined block arguments" do
+ code = described_class.new('code' => "foo { |one, two| one }")
+ code.reconstruct_code.should == "foo { |one, two| one }"
+ end
+
+ it "outputs 'do' and 'end' for multi lined block arguments" do
+ code = described_class.new('code' => "foo { |one, two| one; two }")
+ code.reconstruct_code.should == "foo do |one, two|\n one\n two\nend"
+ end
+
it "doesn't insert same marker twice" do
code = described_class.new('code' => "def foo() 1 end; def bar() 2 end")
code.reconstruct_code.should == ">> method\ndef foo\n 1\nend\n\ndef bar\n 2\nend\n"
View
10 fixtures/block.rb
@@ -0,0 +1,10 @@
+def foo
+ puts "moo"
+end
+
+foo do |blah, blah2|
+ hey
+ hey
+end
+
+foo { |moo, blah| hey }
View
6 processor.rb
@@ -99,7 +99,11 @@ def process_cdecl(exp)
end
def process_lasgn(exp)
- mark(:variable_local) + super
+ if [:masgn, :iter].include?(context[1])
+ super
+ else
+ mark(:variable_local) + super
+ end
end
def process_iasgn(exp)
Please sign in to comment.
Something went wrong with that request. Please try again.