为什么地图和关键字都有一个带有默认参数的额外arity,而set则没有?
这是实施细节还是具体的设计决策?
({:a 2} :b :not-found) ;;=> :not-found
(:b {:a 2} :not-found) ;;=> :not-found
;; This seems counter intuitive.
(#{:a} :b :not-found) ;;=> clojure.lang.ArityException
(:b #{:a} :not-found) ;;=> :not-found
Run Code Online (Sandbox Code Playgroud) 我正在做railstutorial的草稿版本,当我尝试运行时,bundle exec rake test:models我收到此错误消息:
rake aborted!
Errno::EACCES: Permission denied - C:/Users/Alex/Desktop/Workspace/Rails/sample_
app/db/test.sqlite3
C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/test_helper.rb:3:in `<top
(required)>'
C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/helpers/application_helper
_test.rb:1:in `<top (required)>'
Tasks: TOP => test:run => test:units
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
使用--trace:
** Invoke test (first_time)
** Execute test
** Invoke test:run (first_time)
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Execute test:prepare
** Execute test:units
rake aborted!
Errno::EACCES: Permission denied - C:/Users/Alex/Desktop/Workspace/Rails/sample_
app/db/test.sqlite3
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1432:in `unlink'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1432:in `block in remove
_file'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/fileutils.rb:1440:in `platform_suppor …Run Code Online (Sandbox Code Playgroud) 我正在尝试cl-format用来格式化钱.我想要(f 12345.555) ;=> "12,345.56".我得到格式字符串的小数,"~$"我得到逗号分隔符"~:D".我如何组合它们?
我在excel中的数据形状如下:
A B C D
"foo" 5 3 1
"foo" 2 4 5
"foo" 5 5 5
"bar" 1 2 3
"bar" 4 5 7
Run Code Online (Sandbox Code Playgroud)
我想知道在B列,C或D列中的A列和5列中有多少行包含"foo".
换句话说,我想要以下公式=COUNTIFS(A1:A5;"foo";B1:B5;5;C1:C5;5;D1:D5;5),但是B,C和D范围or是一起编辑而不是and'ed.使用excel公式有一个简单的方法吗?
我与投票,评论和帖子有多态关联,如下所示:
class Vote < ActiveRecord::Base
belongs_to :voteable, polymorphic: true
end
class Post < ActiveRecord::Base
has_many :votes, as: :voteable
end
class Comment < ActiveRecord::Base
has_many :votes, as: :voteable
end
Run Code Online (Sandbox Code Playgroud)
当我点击upvote链接时,我发送voteable_type并voteable_id在params中.在投票控制器中,我想使用这两个字符串找到可投票对象,但我发现的唯一解决方案是eval.我认为从参数中评估字符串并不是一个好主意.
class VotesController < ApplicationController
def find_voteable
@voteable = eval("#{params[:vote][:voteable_type]}.find(params[:vote][:voteable_id])")
end
end
Run Code Online (Sandbox Code Playgroud)
有关如何按类名和ID查找ActiveRecord对象的任何建议?或者,有没有更好的方法来做这个不发送参数中的东西?