加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

是否有任何源代码分析工具检测Ruby中未使用的参数?

发布时间:2020-12-17 01:59:15 所属栏目:百科 来源:网络整理
导读:如何在 Ruby中检测未使用的参数? 我知道的选项包括 严格掌握TDD. Heckle(由于ParseTree问题,目前仅适用于Ruby 1.8) 使用诸如RubyMine之类的IDE来检测未使用的参数或自动化重构. 但是,是否有任何源代码分析工具或警告选项可以检测未使用的参数? 背景:我正
如何在 Ruby中检测未使用的参数?

我知道的选项包括

>严格掌握TDD.
> Heckle(由于ParseTree问题,目前仅适用于Ruby 1.8)
>使用诸如RubyMine之类的IDE来检测未使用的参数或自动化重构.

但是,是否有任何源代码分析工具或警告选项可以检测未使用的参数?

背景:我正在做一些重构.我改变了(代码稍微简化):

# Not within the Foo class (therefore can't be as easily accessed by unit testing)
# and in addition,the name of the configuration file is hard-wired
def parse_configuration
  raw_configuration = YAML.load_file("configuration.yml")
  # Do stuff with raw_configuration to produce configuration_options_for_foo
  return configuration_options_for_foo
end

if __FILE__ == $0
  configuration_options_for_foo = parse_configuration
  foo = Foo.new(configuration_options_for_foo)
end

class Foo
  # Now unit tests can call Foo.new_using_yaml("configuration.yml")
  # or use "test_configuration.yml"
  def self.new_using_yaml(yaml_filename)
    # Where I went wrong,forgetting to replace "configuration.yml" with yaml_filename
    raw_configuration = YAML.load_file("configuration.yml")
    # Do stuff with raw_configuration to produce configuration_options_for_foo
    new(configuration_options_for_foo)
  end
end

if __FILE__ == $0
  foo = Foo.new_using_yaml("configuration.yml")
end

解决方法

我认为Laser就是这么做的.

它非常像alpha-y,但似乎做你想要的.

http://github.com/michaeledgar/laser

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读