为什么这个正则表达式在 #ruby 中工作正常,但在 #jruby 中却不起作用?
<Symbol>: /^[\p{Symbol}]+$/
Run Code Online (Sandbox Code Playgroud)
错误“字符属性名称无效”
zlib我正在尝试使用和解码 gzip 压缩的字符串jruby。这是最小的工作示例。
require 'stringio'
require 'zlib'
str = 'H4sIAAAAAAAA/y2NwQrDIBAFfyXstUbWNWrir5RSrEoQUi2JOZSQf6+EHt8wzDtgKd7VVPIG9n7AMwWwYhj1MBkkwtEwcN7vq/NfsAo5MnhFt6Y8g71WcDXW9I5ggVCYHqlH0xE12RJ1N5SIwGBpJ3UPTVOKa41IssGS5z+Vhhs1SdHo9okxXPXzcf4AY45Ve6EAAAA='
input = StringIO.new(str)
puts Zlib::GzipReader.new(input).read
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出
/Users/duke/.rvm/rubies/jruby-1.7.23/bin/jruby --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/duke/RubymineProjects/untitled/gzip_test.rb
Zlib::GzipFile::Error: not in gzip format
initialize at org/jruby/ext/zlib/JZlibRubyGzipReader.java:156
new at org/jruby/ext/zlib/JZlibRubyGzipReader.java:85
(root) at /Users/duke/RubymineProjects/untitled/gzip_test.rb:6
load at org/jruby/RubyKernel.java:1059
(root) at -e:1
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
gzip 压缩的字符串有效。您可以在这里尝试http://www.txtwizard.net/compression
考虑下面的等式:
2**n = A.
我们假设A = 64.
找到n值的最简单方法是什么?
我目前正在使用以下两种方法
A= 64; n = 1; n+=1 while (A >> n) > 0; n-1
A= 64; n = 0; n+=1 until (A == ( 2 ** n));n
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?
说明同样问题的其他方式:
2 =第n个根A如果我知道A的值,我该如何确定n的值?
你们知道JRuby和Jython使用什么解析器来生成JVM字节码吗?是ANTLR还是JavaCC,还是在实现中使用其他解析器?
我有一个网络应用程序,大多数情况下使用MRI Ruby和JRuby.但...
当我使用MRI时,我可以做到这一点.
> rails console
irb(main):001:0> a=Time.new(1,1,1,1,1)
=> 0001-01-01 01:01:00 -0500
Run Code Online (Sandbox Code Playgroud)
即它在指定时间内创建一个新的Time对象.
当我切换到JRuby时,我这样做
> rails console
irb(main):001:0> a=Time.new(1,1,1,1,1)
ArgumentError: wrong number of arguments (5 for 0)
from (irb):2: in `evaluate`
from org/jruby/RubyKernel.java:1088 in `eval`
from /home/user/.rbenv/versions/jruby-1.6.4/lib/ruby/1.8/irb.rb:158 in `eval_input`
from /home/user/.rbenv/versions/jruby-1.6.4/lib/ruby/1.8/
....
Run Code Online (Sandbox Code Playgroud)
如何在JRuby中创建一个Time对象,其中包含我控制的年,月,日,小时和分钟?如果是这样,这可以用于MRI Ruby吗?
我不知道这是否相关,但是
irb(main):002:0> RUBY_VERSION
"1.8.7"
Run Code Online (Sandbox Code Playgroud)
我的问题可能是因为我处于1.8.7模式吗?如果是这样,如何将我的rbenv/jruby-1.6.4安装切换为RUBY_VERSION = 1.9.2?
我刚开始使用JRuby并创建了一个小测试文件:
require 'java'
java_import java.io.File
f = File.new ARGV[0]
Run Code Online (Sandbox Code Playgroud)
当我像这样运行程序时:jruby test.rb file.txt
我收到以下警告:
/Library/Frameworks/JRuby.framework/Versions/1.6.5/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext/object.rb:99 warning: already initialized constant File
该类f实际上是java File类,但我仍然得到警告,任何帮助??
通过查看object.rb我发现这与以下JRuby票有关:http://jira.codehaus.org/browse/JRUBY-3453
我正在使用jruby 1.7.2并设置一个新的rails应用程序.Bundler似乎无法找到必要的(基于java/jruby的宝石)使用:
> bundle
Could not find gem 'neo4j-core (>= 0) ruby' in the gems available on this machine.
Run Code Online (Sandbox Code Playgroud)
如果我指定路径,我得到这个:
> bundle
Fetching gem metadata from https://rubygems.org/.......
Fetching gem metadata from https://rubygems.org/..
Could not find gem 'neo4j-core (>= 0) ruby' in source at ./vendor/gems/neo4j-core.
Source contains 'neo4j-core' at: 2.0.1
Run Code Online (Sandbox Code Playgroud)
也许捆绑者对它的平台感到困惑 - 为什么它会ruby在那里结束这个词呢?我跑了ruby -e "puts RUBY_PLATFORM",这给了我:java
我有一个名为"Backend"的Rails 3.2引擎(可安装).
Ruby平台是JRuby 1.7.0(1.9.3p203).
我还有一个Rails 3.2应用程序(称为my_app),其中Gemfile包含:
gem 'backend', :path => "/home/jacob/projects/backend"
Run Code Online (Sandbox Code Playgroud)
我在my_app的根目录下执行"bundle install"并收到以下错误:
"无法在/ home/jacob/projects/backend的源代码中找到gem'backend(> = 0)java'.源代码不包含任何版本的'backend(> = 0)java'"
backend.gemspec:
$:.push File.expand_path("../lib", \__FILE__)
require "backend/version"
Gem::Specification.new do |s|
s.name = "Backend"
s.version = Backend::VERSION
s.authors = [""]
s.email = [""]
s.homepage = ""
s.summary = ""
s.description = ""
s.files = Dir["{app,config,db,lib}/\**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
end
Run Code Online (Sandbox Code Playgroud) When executing a bash shell script I am using ruby 1.9.3. Then, within the script, I want to switch to JRub (I'm using rvm). I tried switching to JRuby by doing rvm use jruby within the script, but this didn't work, it said:
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command. …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Ruby On Rails中的wicked-pdf创建一个pdf.它在开发模式下运行良好,但是当我在生产中部署时,我收到错误:
wkhtmltopdf is not executable
Run Code Online (Sandbox Code Playgroud)
我有位于以下位置的wkhtmltopdf可执行文件:
rails_root/bin/wkhtmltopdf-i386
Run Code Online (Sandbox Code Playgroud)
Warbler设置为在战争中包含bin文件夹:
config.includes = FileList["classes/*","bin/*"]
Run Code Online (Sandbox Code Playgroud)
我有邪恶的pdf配置为在正确的位置找到bin:
WickedPdf.config = {
:exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
}
Run Code Online (Sandbox Code Playgroud)
我运行warbler然后在jBoss应用服务器上部署战争.当我尝试生成PDF时,我收到有关它不可执行的错误.它在开发模式下运行良好 - 而不是在战争中.
二进制文件的权限应该没问题:
-rwxr-xr-x 1 username group 11446024 Apr 3 11:40 wkhtmltopdf-i386
Run Code Online (Sandbox Code Playgroud)
我尝试使用wkhtmltopdf-binary gem而不是手动包含wkhtmltopdf二进制文件.这在开发模式下也运行良好,但Wicked PDF无法在生产中找到二进制文件.
更新:在生产模式下,我将wicked-pdf配置更改为指向'wkhtmltopdf-binary'gem提供的二进制文件.这也是wkhtmltopdf is not executable错误.路径最终是:jboss-5.1.0.GA/server/default/tmp/3j001-3g0fg5-hf2xi49o-1-hf2xiuld-9q/myrailsapp.war/WEB-INF/gems/gems/wkhtmltopdf-binary-0.9.9.1/bin/wkhtmltopdf_linux_386