• 豁然开朗,感谢分享

  • Sidekiq 任务调度流程分析 at 2017年12月03日

    写的太好了,已经打赏支持,希望楼主一直能保持钻研的热情

  • 你需要谷歌搜索,比如 Ruby pagination

  • 扁平化作用域的简单解释 at 2017年11月03日

    并没有啊,《Ruby 元编程》里面就把这叫做扁平作用域(flat scope)。

  • 我例子给的不太好,这里面的symbol似乎都是Ripper::EVENTS里的,我想最好能有对这些Events的文档(类似于表格),而且一个一个查的话也不全能找到。

    Ripper::EVENTS
    [:BEGIN, :END, :alias, :alias_error, :aref, :aref_field,
     :arg_ambiguous, :arg_paren, :args_add, :args_add_block, :args_add_star,
     :args_new, :array, :assign, :assign_error, :assoc_new,
     :assoclist_from_args, :bare_assoc_hash, :begin, :binary, :block_var,
     :block_var_add_block, :block_var_add_star, :blockarg, :bodystmt,
     :brace_block, :break, :call, :case, :class, :class_name_error, :command,
     :command_call, :const_path_field, :const_path_ref, :const_ref, :def,
     :defined, :defs, :do_block, :dot2, :dot3, :dyna_symbol, :else, :elsif,
     :ensure, :excessed_comma, :fcall, :field, :for, :hash, :if, :if_mod,
     :ifop, :lambda, :magic_comment, :massign, :method_add_arg,
     :method_add_block, :mlhs_add, :mlhs_add_star, :mlhs_new, :mlhs_paren,
     :module, :mrhs_add, :mrhs_add_star, :mrhs_new, :mrhs_new_from_args,
     :next, :opassign, :operator_ambiguous, :param_error, :params, :paren,
     :parse_error, :program, :qwords_add, :qwords_new, :redo, :regexp_add,
     :regexp_literal, :regexp_new, :rescue, :rescue_mod, :rest_param, :retry,
     :return, :return0, :sclass, :stmts_add, :stmts_new, :string_add,
     :string_concat, :string_content, :string_dvar, :string_embexpr,
     :string_literal, :super, :symbol, :symbol_literal, :top_const_field,
     :top_const_ref, :unary, :undef, :unless, :unless_mod, :until, :until_mod,
     :var_alias, :var_field, :var_ref, :void_stmt, :when, :while, :while_mod,
     :word_add, :word_new, :words_add, :words_new, :xstring_add,
     :xstring_literal, :xstring_new, :yield, :yield0, :zsuper, :CHAR,
     :__end__, :backref, :backtick, :comma, :comment, :const, :`cvar, :embdoc,
     :embdoc_beg, :embdoc_end, :embexpr_beg, :embexpr_end, :embvar, :float,
     :gvar, :heredoc_beg, :heredoc_end, :ident, :ignored_nl, :int, :ivar, :kw,
     :label, :lbrace, :lbracket, :lparen, :nl, :op, :period, :qwords_beg,
     :rbrace, :rbracket, :regexp_beg, :regexp_end, :rparen, :semicolon, :sp,
     :symbeg, :tlambda, :tlambeg, :tstring_beg, :tstring_content,
     :tstring_end, :words_beg, :words_sep]
    ``
    
    • 1 🙋 🙋
  • 非常酷,感谢分享

  • 可以用 lambda

    change = lambda do
      num = [1]
    end
    change.call
    
  • 官方文档已经讲了很清楚了

    new(size=0, default=nil) new(array) new(size) {|index| block }

    In the first form, if no arguments are sent, the new array will be empty. When a size and an optional default are sent, an array is created with size copies of default. Take notice that all elements will reference the same object default.

  • 应用了元编程,开心哦 at 2017年09月12日

    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live

  • Manjaro + gnome