@hexawing 我觉得这就是你思想有误了啊,楼主生成的是 7 位的随机字母,重复来说概率问题。
@teddyinfi 这样就跟 method(:passive).source 一样了,不用 to_s 了 哈哈,谢谢了
self.method(:passive).source == method(:passive).source #=> true
method(:passive).source #可以输出,而且是String类型。不过需要在开头require 'method_source'
instance_method(:passive).source #提示报错,undefined method `instance_method' for main:Object (NoMethodError),还没搞明白。。
@teddyinfi @IChou 昨天工作着急下班,刚才测试, 注意到
self.method(:passive).source.display # 能输出passive方法的所有东西
self.method(:passive).source.display.class #输出跟上边完全一样
p self.method(:passive).source.display.class #输出为NilClass
虽然有输出,但是并不能引用。(已经在开头 require 'method_source')
@1c7 就是想从外部获取 passive 方法中的某个关键字,比如上边
m << { :version=>@body.scan(/<p>Version ([\d\.]+)<\/p>/)[0][0] }
这行中的关键字“version”
@rubyist518 大概意思是把 passive 方法放到 class 类中,然后用类的 method 输出 source?百度找不到 source 什么鬼,求指教。
@teddyinfi @IChou 输出看了看:
[:each_index, :join, :rotate, :rotate!, :sort!, :sort_by!, :collect!, :map!, :select!, :keep_if, :values_at, :delete_at, :to_h, :delete_if, :reject!, :transpose, :include?, :rassoc, :uniq!, :assoc, :compact, :compact!, :flatten!, :shuffle!, :shuffle, :fill, :permutation, :combination, :sample, :repeated_permutation, :repeated_combination, :flatten, :bsearch, :product, :bsearch_index, :&, :*, :+, :-, :sort, :count, :find_index, :select, :reject, :collect, :map, :first, :any?, :pack, :reverse_each, :zip, :take, :take_while, :drop, :drop_while, :cycle, :sum, :uniq, :|, :insert, :index, :rindex, :<=>, :<<, :clear, :replace, :==, :[], :[]=, :empty?, :eql?, :reverse, :reverse!, :concat, :max, :min, :inspect, :length, :size, :each, :delete, :to_ary, :slice, :slice!, :to_a, :to_s, :dig, :hash, :frozen?, :at, :fetch, :last, :push, :pop, :shift, :unshift, :find, :entries, :sort_by, :grep, :grep_v, :detect, :find_all, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :all?, :one?, :none?, :minmax, :min_by, :max_by, :minmax_by, :member?, :each_with_index, :each_entry, :each_slice, :each_cons, :each_with_object, :chunk, :slice_before, :slice_after, :slice_when, :chunk_while, :lazy, :instance_of?, :kind_of?, :is_a?, :tap, :public_send, :define_singleton_method, :method, :public_method, :remove_instance_variable, :instance_variable_set, :singleton_method, :extend, :to_enum, :enum_for, :===, :=~, :!~, :respond_to?, :freeze, :object_id, :send, :display, :nil?, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variable_get, :instance_variables, :instance_variable_defined?, :!, :!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__]
真的好像没有
大神你们先讨论,,我去 try it,,
我发的时候手动排版了啊,我错了。