Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
c想睡觉
@rc13520822803
会员
第 34699 位会员 / 2018-03-27

[email protected]
1 篇帖子 / 10 条回帖
0 关注者
1 正在关注
1 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 生成随机字母的精妙代码 at 2018年05月18日

    @hexawing 我觉得这就是你思想有误了啊,楼主生成的是 7 位的随机字母,重复来说概率问题。

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月17日

    @teddyinfi 这样就跟 method(:passive).source 一样了,不用 to_s 了 哈哈,谢谢了

    self.method(:passive).source == method(:passive).source  #=> true
    
    
  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月17日

    @rubyist518

    method(:passive).source  #可以输出,而且是String类型。不过需要在开头require 'method_source'
    instance_method(:passive).source #提示报错,undefined method `instance_method' for main:Object (NoMethodError),还没搞明白。。
    
  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月17日

    @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')

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月16日

    @teddyinfi 谢谢大哥,🇻

    @IChou

    root@localhost:/home# gem install method_source
    
    

    命令执行后,确实可以了

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月16日

    @1c7 就是想从外部获取 passive 方法中的某个关键字,比如上边

    m << { :version=>@body.scan(/<p>Version ([\d\.]+)<\/p>/)[0][0] }
    
    

    这行中的关键字“version”

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月16日

    @rubyist518 大概意思是把 passive 方法放到 class 类中,然后用类的 method 输出 source?百度找不到 source 什么鬼,求指教。

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月16日

    @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__]
    

    真的好像没有

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月16日

    大神你们先讨论,,我去 try it,,

  • 有没有方法可以获取定义的 def 方法中的内容求大神帮帮忙小弟还在敲代码工作 at 2018年05月16日

    😭 我发的时候手动排版了啊,我错了。

关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English