lib/opal/parser.rb
# Used to generate optimized attr_reader, attr_writer and
# attr_accessor methods. These are optimized to avoid the added
# cost of converting the method id's into jsid's at runtime.
#
# This method will only be called if all the given ids are strings
# or symbols. Any dynamic arguments will default to being called
# using the Module#attr_* methods as expected.
#
# @param [Symbol] meth :attr_{reader,writer,accessor}
# @param [Array<Sexp>] attrs array of s(:lit) or s(:str)
# @return [String] precompiled attr methods


This method will only be called if all the given ids are strings
or symbols. Any dynamic arguments will default to being called
using the Module#attr_* methods as expected.
This method will only be called if all the given ids are strings or symbols . Any dynamic arguments will default to being called using the Module#attr_ * methods as expected .
def attr_optimize(meth, attrs)
      out = []
      attrs.each do |attr|
        mid  = attr[1]
        ivar = "@#{mid}".to_sym
        pre  = @scope.proto
        unless meth == :attr_writer
          out << process(s(:defn, mid, s(:args), s(:scope, s(:ivar, ivar))), :stmt)
        end
        unless meth == :attr_reader
          mid = "#{mid}=".to_sym
          out << process(s(:defn, mid, s(:args, :val), s(:scope,
                    s(:iasgn, ivar, s(:lvar, :val)))), :stmt)
        end
      end
      out.join ", \n#@indent"
    end
def attr_optimize ( meth , attrs ) out = [ ] attrs . each do | attr | mid = attr [ 1 ] ivar = "@#{mid}" . to_sym pre = @scope . proto unless meth == :attr_writer out << process ( s ( :defn , mid , s ( :args ) , s ( :scope , s ( :ivar , ivar ) ) ) , :stmt ) end unless meth == :attr_reader mid = "#{mid}=" . to_sym out << process ( s ( :defn , mid , s ( :args , :val ) , s ( :scope , s ( :iasgn , ivar , s ( :lvar , :val ) ) ) ) , :stmt ) end end out . join ", \n#@indent" end
Used to generate optimized attr_reader, attr_writer and
attr_accessor methods.
Used to generate optimized attr_reader attr_writer and attr_accessor methods .
precompiled attr methods
precompiled attr methods
String
meth
<not_specific>
attrs
<not_specific>
<not_specific>
attrs array of s(:lit) or s(:str)
attrs array of s ( : lit ) or s ( : str )