草庐IT

date_end

全部标签

ruby - Rspec 返回语法错误 "unexpected ' {', expecting keyword_end"

这在一台装有Ruby的机器上有效,但在另一台机器上无效。代码:describe'testingreversestringdifferentways'dolet:thing{'cba321'}it'thesystemmethod'dosource='123abc'result=source.reverseexpect(result).toeq'cba321'endend错误:SyntaxError:/home/michael/Dropbox/90_2019/work/code/ruby__rails/ruby/reverse_string_tests_timing/test_spec.r

ruby-on-rails - Rails Date.today 反射(reflect)了服务器部署日期

我有一个Rails应用程序,它显示事件事件(今天或之后的事件)。scope:active,where("event_date>=?",Date.today).order("event_dateASC")在本地一切顺利。但是在生产服务器上,查询正在使用部署日期进行比较。这是日志SELECT"events".*FROM"events"WHERE"events"."school_id"=32AND(roster_idin(45)orroster_idISNULL)AND(event_date>='2014-09-18')按事件日期升序排序但是如果在生产环境中从控制台检查,它显示正确1.9.3

ruby - 使用 do...end block 时 map、select 等的不同行为

这个问题在这里已经有了答案:Rubyblockandunparenthesizedarguments(1个回答)关闭7年前。当我使用map、select和其他Enumerable时,我注意到以下行为差异方法。假设我们有如下哈希:h={a:1}下面的代码按预期打印select的输出。ph.select{|k,v|true}#=>{:a=>1}但是,下面的代码显示输出是一个Enumerator,即使已经提供了一个block。ph.selectdo|k,v|trueend#=>#1}:select>知道为什么会出现这种行为差异吗?我经常遇到这个问题,因为我在工作时一直使用inspectp,这

ruby-on-rails - ruby If .. Else .. End/Increment : Syntax Error

这个问题在这里已经有了答案:Unexpectedkeyword_enderror,yetsyntaxseemsfine(2个答案)关闭8年前。我创建了一个类方法,它循环访问一个Order对象数组。我正在使用那里的数据来构建哈希。我在iterable中的一个ifblock是:if!(report_hash[user_id][reason])report_hash[user_id][reason]=1elsereport_hash[user_id][reason]++end当我运行这个方法时,我得到:.rb:66syntaxerror,unexpectedkeyword_end(Synta

ruby - 使用 start_time 和 end_time 的 ice_cube gem 单次事件

这里一定有一些简单的东西被忽略了......我一直在尝试各种方法来创建基本的IceCube计划(https://github.com/seejohnrun/ice_cube)。总体目标是使用IceCube允许“房间预订”rails应用程序中的“价格表”。第一种情况是创建一个具有特定start_time和end_time的基本计划-只发生一次。IceCube可以做到这一点,对吗?计划将从start_time开始,在end_time结束。我希望能够检查日期或时间是否occurs_on?此时间表以确定是否应调整房价。因此,在控制台中,我尝试创建一个基本时间表,并希望它从现在开始5.days发

ruby - 为什么分配变量时 do/end block 的行为/返回不同?

puts[1,2,3].mapdo|x|x+1end.inspect对于ruby​​1.9.2这会返回ruby1.8.7:#1#2#3分配一个变量...x=[1,2,3].mapdo|x|x+1end.inspectputsx[2,3,4]mustacheblock按预期工作:puts[1,2,3].map{|x|x+1}.inspect[2,3,4] 最佳答案 puts[1,2,3].mapdo|x|x+1end.inspect解析为:puts([1,2,3].map)do|x|x+1end.inspect即map在没有block

ruby - ruby 中 'do .. end' 和 "{..}" block 的不同行为

这个问题在这里已经有了答案:WhatisthedifferenceorvalueoftheseblockcodingstylesinRuby?(7个答案)关闭6年前。抱歉,如果这个问题是重复的。但是我找不到用法上的区别。当我运行以下代码时,我得到了不同的答案。我从大多数教程中看到,使用“do...end”与“{...}”block相同。includeComparablea=[1,4,2,3,5]pa.sortdo|x,y|yxend输出显示为=[1,2,3,4,5]但是当我这样跑的时候...includeComparablea=[1,4,2,3,5]pa.sort{|x,y|yx}输出

ruby-on-rails - 为什么介于两者之间? ruby 中 Date 和 DateTime 的工作方式不同?

doc说:between?(min,max)publicReturnstrueifthecurrentobject’stimeiswithinthespecifiedminandmaxtime.在ruby中:>>DateTime.now.between?(DateTime.now,DateTime.now+1)=>false>>Date.today.between?(Date.today,Date.today+1)=>true通过使用.current在Rails中,差异变得更加明显,因为您特别假设此方法在DateTime上会有类似的行为。和Date:>>DateTime.current

ruby - Instance_eval 不适用于 do/end block ,仅适用于 {} block

这个问题在这里已经有了答案:Rubyblockandunparenthesizedarguments(1个回答)RubyBlockSyntaxError[duplicate](1个回答)关闭8年前。如果我有一个类:classKlassWithSecretdefinitialize@secret=99endend然后运行:putsKlassWithSecret.new.instance_eval{@secret}它打印99,但如果我运行:putsKlassWithSecret.new.instance_evaldo@secretend它返回一个错误:`instance_eval':参数数

ruby-on-rails - Assets :precompile end of file reached

我正在尝试在我的Rails4应用程序上运行assets:precompile,但我不断收到:rakeaborted!endoffilereached在capistrano提示同样的错误后,我在我的VPS上运行这个命令。有什么想法吗?[deploy@skateboxesskateboxes]$cd/var/www/skateboxes/releases/20131024204508&&(RAILS_ENV=production/usr/local/rvm/bin/skateboxes_rakeassets:precompile)rakeaborted!endoffilereached/v