草庐IT

working_dir

全部标签

ruby - 为什么没有 Module.method_defined?(:method) work correctly?

我正在尝试使用Module.method_defined?(:method)检查模块中是否定义了方法,它返回false,应该返回true。moduleSomethingdefself.another1endendSomething.methods列出了“另一个”,但Something.method_defined?(:another)返回false。这可能不起作用,因为该方法是在self上定义的吗?如果是这种情况,除了使用method_defined?之外,还有其他方法可以检查模块上是否定义了方法吗? 最佳答案 要知道模块是否有模块

ruby - 导轨 : How do I require NumberHelper and make it work?

我正在尝试编写一个简单的Sinatra东西,但我需要操作包中的ActionView::Helpers::NumberHelper。http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html问题是,如何安装和使用它?irb(main):001:0>require'action_view/helpers/number_helper'irb(main):002:0>number_with_precision(1)NoMethodError:undefinedmethod`number_with_precisi

ruby - Ruby 的 Dir.glob() 最简洁的 Clojure 等价物是什么?

在Clojure中做这样的事情最简单的方法是什么?require'csv'Dir["data/*.csv"].eachdo|file|File.readlines(file).eachdo|line|x,y,z=*CSV.parse_line(line)#processthisdataendend 最佳答案 这是我见过的最短的:(require'[clojure.java.io:asio])(filter#(.endsWith(.getName%)".csv")(file-seq(io/filedir))))来自https://gi

ruby-on-rails - 自定义验证 :on => :create not working

我有一个自定义验证方法,我只想在创建时执行:validate:post_count,:on=>:createdefpost_count#validatestuffend但是,它会在更新时被触发(除了在创建时)。:on=>:create选项是否不适用于自定义验证方法? 最佳答案 据我所知,没有:on选项。使用validate_on_create:post_count相反。还有validate_on_update。您可以阅读有关此方法的信息here. 关于ruby-on-rails-自定义验

ruby-on-rails - rails : rbenv rehash not working (rbenv-shim exists)

我正在尝试在安装新gem后重新哈希rbenv它在我的ubuntu服务器上给了我这些错误rbenv:cannotrehash:/home/deployer/.rbenv/shims/.rbenv-shimexists但是.rbenv-shims不存在 最佳答案 可能是issuewithdirectorypermissions@sstephenson/rbenv:FWIW-Ialsohadthisproblem,andhadtochangepermissionsonthedirwhereitwascheckingforthe.rbenv

ruby - 如何修复意外的 'sudo bundle install dir_name' ?

我不小心运行了sudobundleinstallsmtp_mail,现在我所有的gem都在我的Rails应用程序中这个名为smtp_mail的目录中。我不确定gem的默认位置?而且,我的Rails应用程序在启动时提示。有什么办法可以恢复原状吗? 最佳答案 经过一番谷歌搜索后,我找到了答案只需运行:sudobundleinstall--system然后您会将您的gem放回到它们适当的系统目录中。 关于ruby-如何修复意外的'sudobundleinstalldir_name'?,我们在S

ruby - Dir.glob 获取文件夹中的所有 csv 和 xls 文件

folder_to_analyze=ARGV.firstfolder_path=File.join(Dir.pwd,folder_to_analyze)unlessFile.directory?(folder_path)puts"Error:#{folder_path}noesunfoldervalido."exitenddefget_csv_file_paths(path)files=[]Dir.glob(path+'/**/*.csv').eachdo|f|files我正在尝试在Ruby中制作一个简单的脚本,允许我从命令行调用它,例如rubycounter.rbmailing_li

ruby - RVM + Zsh "RVM is not a function, selecting rubies with ' rvm 使用.. .' will not work"

首先我要说我不是命令行专家,所以我真的几乎不知道自己在做什么。我无法让RVM和oh-my-zsh一起玩得很好。我尝试了几种不同的解决方案,其中一些是在SO上发布的,但我发现似乎没有任何解决方案可以解决问题。最初,其他人在我的机器上安装了RVM。后来我自己设置了oh-my-zsh,记得当时遇到了很多麻烦。除了这两行,我的.zhsrc文件是完全默认的exportPATH=$HOME/bin:/usr/local/bin:/usr/local/rvm/bin:$PATH#prettysurethislinedoesnothing,althoughI'veseenthisfixaround#s

ruby-on-rails - rake 数据库 :migration not working on travis-ci build

我正尝试在Travis-CI上从github构建我的RubyonRails项目,但我遇到了迁移问题。它运行一个用于迁移的rake任务,但它在之后提示相同的迁移步骤。它遵循我的.travis.yml文件:language:rubyrvm:-1.9.2before_script:-"rakedb:migrateRAILS_ENV=test"这是构建输出:1Usingworker:ruby4.worker.travis-ci.org:travis-ruby-32345$cd~/builds678$gitclone--depth=100--quietgit://github.com/rafae

ruby - 总和(&:x) not working any more

我在我的Rails应用程序(4.1.2)中使用payments.sum(&:price)。自从我从Ruby1.9.3更新到2.1.2后,出现了以下错误:wrongnumberofarguments(1for2..3)这些变体有效:payments.map(&:price).sumpayments.to_a.sum(&:price)我必须重写我的代码还是我遗漏了什么?谢谢! 最佳答案 来自documentation:sum(*args)Calculatesthesumofvaluesonagivencolumn.Thevalueisr