Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor eval_cons.

  • Loading branch information...
commit 7a0100ff47b35296bb3dab0d327c15295c4acdea 1 parent d12d1fa
@kivikakk kivikakk authored
Showing with 28 additions and 22 deletions.
  1. +28 −22 lib/rouge/context.rb
View
50 lib/rouge/context.rb
@@ -180,34 +180,40 @@ def eval_cons(form)
args = args.map {|f| eval(f)}
backtrace_fix("(rouge):?:lambda: ", form) do
- num_args = args.length
- case fun
- when Symbol
- if num_args == 1 || num_args == 2
- default = args[1]
- if args[0].is_a? Hash
- args[0].fetch(fun) { default }
- else
- default
- end
- else
- raise ArgumentError.new "Wrong number of args (#{num_args}) passed to ruby/Symbol :#{fun}"
- end
- when Hash
- if num_args == 1 || num_args == 2
- default = args[1]
- fun.fetch(args[0]) { default }
- else
- raise ArgumentError.new "Wrong number of args (#{num_args}) passed to ruby/Hash"
- end
+ eval_call(fun, args, block)
+ end
+ end
+ end
+
+ def eval_call(fun, args, block)
+ num_args = args.length
+ case fun
+ when Symbol
+ if num_args == 1 || num_args == 2
+ default = args[1]
+ if args[0].is_a? Hash
+ args[0].fetch(fun) { default }
else
- fun.call *args, &block
+ default
end
+ else
+ raise ArgumentError,
+ "Wrong number of args (#{num_args}) passed to ruby/Symbol :#{fun}"
end
+ when Hash
+ if num_args == 1 || num_args == 2
+ default = args[1]
+ fun.fetch(args[0]) { default }
+ else
+ raise ArgumentError,
+ "Wrong number of args (#{num_args}) passed to ruby/Hash"
+ end
+ else
+ fun.call(*args, &block)
end
end
- def backtrace_fix name, form, &block
+ def backtrace_fix(name, form, &block)
begin
block.call
rescue Exception => e
Please sign in to comment.
Something went wrong with that request. Please try again.