rewrite_bmethod (UnifiedRuby)

    # File lib/unified_ruby.rb, line 58
      def rewrite_bmethod(exp)
        _, args, body = exp

        args ||= s(:array)
        body ||= s(:block)

        args = s(:args, args) unless args[0] == :array

        args = args[1] if args[1] && args[1][0] == :masgn # TODO: clean up
        args = args[1] if args[1] && args[1][0] == :array
        args[0] = :args

        # this is ugly because rewriters are depth first.
        # TODO: maybe we could come up with some way to do both forms of rewriting.
        args.map! { |s|
          if Sexp === s
            case s[0]
            when :lasgn then
              s[1]
            when :splat then
              "*#{s[1][1]}""*#{s[1][1]}"
            else
              raise "huh?: #{s.inspect}"
            end
          else
            s
          end
        }

        body = s(:block, body) unless body[0] == :block
        body.insert 1, args

        s(:scope, body)
      end