ruby-2.0

How to run Ruby 2.0 with JRuby 1.7?

不羁岁月 提交于 2019-11-29 05:11:01
问题 What is the best way to get JRuby to run in 2.0 mode? 回答1: For a specific script, you can use the --2.0 option: jruby --2.0 -S rails s For setting 2.0 as the default value, set JRUBY_OPTS : export JRUBY_OPTS=--2.0 You can also set the value in ~/.jrubyrc : compat.version=2.0 来源: https://stackoverflow.com/questions/15281036/how-to-run-ruby-2-0-with-jruby-1-7

Rails - Get the time difference in hours, minutes and seconds

孤街醉人 提交于 2019-11-29 01:07:29
I'm looking for an idiomatic way to get the time passed since a given date in hours, minutes and seconds. If the given date is 2013-10-25 23:55:00 and the current date is 2013-10-27 20:55:09, the returning value should be 45:03:09. The time_difference and time_diff gems won't work with this requirement. You can try with this: def time_diff(start_time, end_time) seconds_diff = (start_time - end_time).to_i.abs hours = seconds_diff / 3600 seconds_diff -= hours * 3600 minutes = seconds_diff / 60 seconds_diff -= minutes * 60 seconds = seconds_diff "#{hours.to_s.rjust(2, '0')}:#{minutes.to_s.rjust(2

Possible to get Rails 4 working on Windows?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 23:41:22
I'm working on a Rails 4 (using the release candidate) project and now need to collaborate with someone on a Windows machine. I can't even get a basic webpage to come up, however :(. It was quite a pain even installing sqlite3 using Ruby 2.0. Now, when I try to get a webpage up (I just created a dummy /home/index controller and view), I get this error: Showing C:/Users/me/RubymineProjects/test_project/app/views/layouts/application.html.erb where line #6 raised: (in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/turbolinks-1.1.1/lib/assets/javascripts/turbolinks.js.coffee) Extracted source (around

Named parameters in Ruby 2

风格不统一 提交于 2019-11-28 19:07:35
I don't understand completely how named parameters in Ruby 2.0 work. def test(var1, var2, var3) puts "#{var1} #{var2} #{var3}" end test(var3:"var3-new", var1: 1111, var2: 2222) #wrong number of arguments (1 for 3) (ArgumentError) it's treated like a hash. And it's very funny because to use named parameters in Ruby 2.0 I must set default values for them: def test(var1: "var1", var2: "var2", var3: "var3") puts "#{var1} #{var2} #{var3}" end test(var3:"var3-new", var1: 1111, var2: 2222) # ok => 1111 2222 var3-new which very similar to the behaviour which Ruby had before with default parameters'

Unexpected Return (LocalJumpError)

被刻印的时光 ゝ 提交于 2019-11-28 18:10:54
What is the problem with this Ruby 2.0 code? p (1..8).collect{|denom| (1...denom).collect{|num| r = Rational(num, denom) if r > Rational(1, 3) and r < Rational(1, 2) return 1 else return 0 end } }.flatten The error is in block (2 levels) in <main>': unexpected return (LocalJumpError) . I want to create a flat list containing n ones (and the rest zeroes) where n is the number of rational numbers with denominators below 8 which are between 1/3 and 1/2. ( it's a Project Euler problem ). So I'm trying to return from the inner block. You can't return inside a block in Ruby * . The last statement

Ruby 2.0 iconv replacement

自古美人都是妖i 提交于 2019-11-28 17:11:43
问题 I don't know Ruby but want to run an script where: D:/Heather/Ruby/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- iconv (LoadError) it works somehow if I comment iconv code but it will be much better if I can recode this part: return Iconv.iconv('UTF-8//IGNORE', 'UTF-8', (s + ' ') ).first[0..-2] without iconv . Maybe I can use String#encode here somehow? 回答1: Iconv was deprecated (removed) in 1.9.3. You can still install it. Reference Material if

Can't install Ruby 2.0.0-p0 with RVM. Error running 'make -j8'

可紊 提交于 2019-11-28 03:43:15
问题 I tried to install Ruby 2 using RVM today and it failed. I updated RVM, all my brew formulas and whatnot. This is what I get: admin:/$ rvm install ruby-2.0.0-p0 Searching for binary rubies, this might take some time. No binary rubies available for: osx/10.8/x86_64/ruby-2.0.0-p0. Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies. Installing requirements for osx, might require sudo password. Already up-to-date. Certificates in '/usr/local/etc/openssl

Installing Ruby 2.0 and Rails 4.0.0beta on AWS EC2

拟墨画扇 提交于 2019-11-28 02:57:54
Installing Ruby 2.0.0 and Rails 4.0.0beta1 on the default Amazon EC2 Linux install (Amazon Linux AMI 2012.09.1) goes smoothly. But openssl gets in the way (eg http://railsapps.github.com/openssl-certificate-verify-failed.html ) and weird either prevent openssl from getting installed or causing the RubyGem package manager from installing rails. How can I work around these problems? Log into your brand new instance: [19:59:22] paul:~ $ ssh -i ~/.ssh/server.pem ec2-user@your.ip __| __|_ ) _| ( / Amazon Linux AMI ___|\___|___| https://aws.amazon.com/amazon-linux-ami/2012.09-release-notes/ and

How to install Ruby 2 on Ubuntu without RVM

会有一股神秘感。 提交于 2019-11-28 02:49:56
I want to install ruby 2.0 using sudo apt-get install ruby2.0 But there isn't available package for ruby2.0 I want to install it using apt-get install the same like ruby 1.9.1 Any suggestions? danmanstx sudo apt-get -y update sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev cd /tmp wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p451.tar.gz tar -xvzf ruby-2.0.0-p451.tar.gz cd ruby-2.0.0-p451/ ./configure --prefix=/usr/local make sudo make install from here How do I install ruby 2.0.0 correctly on Ubuntu 12.04? UPDATE for ruby 2.1.5 sudo apt-get

Ruby on Rails - “Add 'gem sqlite3'' to your Gemfile”

眉间皱痕 提交于 2019-11-27 22:00:37
I'm a complete n00b on Rails with only beginner knowledge of Ruby. I plan on studying Ruby more before I really learn Rails, but I'm waayy too curious for my own good. Anyway, I was following the tutorial, but I got stuck when it said to type "rails server" in the blog directory. It states, "Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile." So I quit the server, installed sqlite3, reinstated the server...only to get this message again. sqlite3 doesn't show up when I do "gem list", but I do see the folder in my Root Ruby directory. If it