草庐IT

java - 无法在 Eclipse 中编译枚举

全部标签

ruby - 使用 RVM,但无法设置当前的 Ruby 版本 (Ubuntu 11.10)

我最近在全新安装的Ubuntu11.10上安装了RVM,但不知道如何开始使用特定的ruby​​版本。我已经安装了Ruby1.8.7和1.9.2,它们在列表中显示得很好:$rvmlistrvmrubiesruby-1.8.7-p352[i386]ruby-1.9.2-p290[i386]当我尝试使用“use”命令时,一切似乎都很好:$rvmuse1.9.2Using/usr/share/ruby-rvm/gems/ruby-1.9.2-p290Running/usr/share/ruby-rvm/hooks/after_use但是当我测试当前的ruby​​版本时,我得到了当你根本没有RV

ruby-on-rails - 无法从类内部访问私有(private)方法?

为什么我无法从类封装的方法中访问下面代码中的私有(private)方法check_url?classLink{:in=>[true,false]}validates:url,:presence=>true#===============================================================#=classmethods(accessiblefromoutsidewithoutaninstance)=#===============================================================classurl,:i

ruby-on-rails - 无法让 Paperclip 正确设置我的 S3 URL

我在Rails4应用程序中使用回形针和aws-sdkgem。我在paperclip.rb配置中定义了:path选项,没有:url选项:Paperclip::Attachment.default_options[:path]=":class/:attachment/:id_partition/:style/:filename"它会像这样保存我上传的图片:http://s3.amazonaws.com/mybucket-development/profiles/avatars/000/000/026/original/image_file_name.png?1420575189没问题,它被

ruby-on-rails - Capybara::ElementNotFound:无法找到文件字段 "file"

我正在测试文件上传,即CSV。在我的代码和浏览器HTML中,我找到了文件字段,但在测试capybara时找不到文件字段。我努力尝试不同的方法,但无法解决问题。这里部分看起来像这样:#add_file_box%div.msg%h1.page-header="UploadaCSV"%h4.title=form_tagdummy_path,multipart:true,class:"upload_csv"do=hidden_field_tag:dmp_id,@dmp.id.form-group.input-group%span.input-group-btn%span.btn.btn-pri

ruby-on-rails - 无法写入未知属性 `scrapbook_entry_id'

正在尝试将数据添加到scrapbook_entries的连接表中,其中has_one:scrapbook和has_one:recipe。:recipe和:scrapbook已经存在。我正在尝试添加它们以将它们与scrapbook_entries表链接起来。form_for添加到scrapbook_entries表:scrapbook_entries_path(params[:id]))do|f|%>@recipe.id%>剪贴簿_条目_Controller:defcreate@recipe=Recipe.find(params[:scrapbook_entry][:recipe_id]

ruby - 无法使用 Vagrant 转发端口访问主机上的 Sinatra 应用程序

在使用rubyapp.rb和foremanstart启动我的Sinatra应用程序后,我无法使用localhost和主机上的相应端口访问我的应用程序。我还能够从客户机的shell中curl到应用程序,而在主机上curl请求失败。据我所知,guest计算机上不应该安装防火墙,因为我使用的是VagrantUbuntu镜像。我的Vagrantfile如下:Vagrant.configure('2')do|config|config.vm.box='precise32'config.vm.box_url='http://files.vagrantup.com/precise32.box'con

ruby - 如何在 Ruby 中使用 C# 样式枚举?

我只想知道在Ruby中模拟C#样式枚举的最佳方法。 最佳答案 Specifically,Iwouldliketobeabletoperformlogicaltestsagainstthesetofvaluesgivensomevariable.Examplewouldbethestateofawindow:"minimized,maximized,closed,open"如果您需要将枚举映射到值(例如,您需要最小化为0,最大化为100等),我会使用符号散列值,如下所示:WINDOW_STATES={:minimized=>0,:ma

Ruby:是否有类似 Enumerable#drop 的东西返回枚举器而不是数组?

我有一些大的固定宽度文件,我需要删除标题行。跟踪迭代器似乎不是很惯用。#ThisiswhatIdonow.File.open(filename).each_line.with_indexdo|line,idx|ifidx>0...endend#ThisiswhatIwanttodobutIdon'tneeddrop(1)toslurp#thefileintoanarray.File.open(filename).drop(1).each_linedo{|line|...}Ruby的成语是什么? 最佳答案 这稍微更整洁:File.op

ruby - 无法通过 rvm 安装 compass

在Ubuntu11.10中,我是一个快乐且无忧的compass用户。我升级到12.04并遇到了这个问题:Compass(ruby)encodingerror我以某种方式设法解决了通过rvm在我的一台计算机上安装ruby​​的问题,但现在我在另一台计算机上遇到了不同的错误(具有相同的初始问题)。我安装了ruby​​和compass并默认使用全局gemset:gemlist***LOCALGEMS***bundler(1.1.3)chunky_png(1.2.5)compass(0.12.1)fssm(0.2.9)rake(0.9.2.2)rubygems-bundler(1.0.0)rv

ruby - 枚举器如何在 Ruby 1.9.1 中工作?

这个问题不是关于如何在Ruby1.9.1中使用枚举器,而是我很好奇它们是如何工作的。这是一些代码:classBunkdefinitialize@h=[*1..100]enddefeachif!block_given?enum_for(:each)else0.upto(@h.length){|i|yield@h[i]}endendend在上面的代码中我可以使用e=Bunk.new.each,然后是e.next,e.next得到每个连续的元素,但它究竟是如何暂停执行然后在正确的位置恢复的?我知道如果将0.upto中的yield替换为Fiber.yield则很容易理解,但此处并非如此。这是一