我使用Ruby on Rails v4.1.0创建了一个新的应用程序.尝试在Windows上启动服务器或控制台时,我遇到以下错误:
$ rails server
Booting WEBrick
Rails 4.1.0 application starting in development on ....
Exiting
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:199:
in `rescue in create_default_data_source':
No timezone data source could be found. To resolve this, either install
TZInfo::Data (e.g. by running `gem install tzinfo-data`) or specify a zoneinfo
directory using `TZInfo::DataSource.set(:zoneinfo, zoneinfo_path)`.
(TZInfo::DataSourceNotFound)
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:196:
in `create_default_data_source'
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
据维基百科称,猴子补丁是:
一种在不改变原始源代码的情况下扩展或修改动态语言的运行时代码的方法.
来自同一条目的以下陈述使我感到困惑:
在Ruby中,术语monkey patch被误解为对类的任何动态修改,并且通常用作在运行时动态修改任何类的同义词.
我想知道Ruby修补猴子的确切含义.它是在做类似下面的事情,还是其他什么?
class String
def foo
"foo"
end
end
Run Code Online (Sandbox Code Playgroud) 我这几天一直在研究Ruby,我注意到Ruby on Rails.
两者有什么区别?他们一起工作吗?语法是否相同?
我们的应用程序是使用Twitter登录的人员挖掘名称.
Twitter在一个字符串中提供全名.
例子
1. "Froederick Frankenstien"
2. "Ludwig Van Beethoven"
3. "Anne Frank"
Run Code Online (Sandbox Code Playgroud)
我想根据找到的第一个(空格)将字符串拆分为两个变量(first和last)" ".
Example First Name Last Name
1 Froederick Frankenstein
2 Ludwig Van Beethoven
3 Anne Frank
Run Code Online (Sandbox Code Playgroud)
我很熟悉,String#split但我不确定如何只拆分一次.最接受Ruby-Way™(优雅)答案.
从这段代码我不知道两种方法之间的区别,collect和each.
a = ["L","Z","J"].collect{|x| puts x.succ} #=> M AA K
print a.class #=> Array
b = ["L","Z","J"].each{|x| puts x.succ} #=> M AA K
print b.class #=> Array
Run Code Online (Sandbox Code Playgroud) 我在截屏视频中看到了这个,只是想知道在这种情况下'='符号是做什么的.
def express_token=(token)
...
end
Run Code Online (Sandbox Code Playgroud)
我会理解是否是这样的 -
def express_token(token = nil)
Run Code Online (Sandbox Code Playgroud)
上面的(第二个代码片段)表示将nil设置为tokens参数的默认值.但是,在第一个代码段中,'='位于括号内.
提前致谢.
转换它的最佳方法是什么?
[[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []]
Run Code Online (Sandbox Code Playgroud)
成
[["Club three Team one", 7800], ["Club three Team two", 7801], ["Club four Team one", 7807], ["Club four Team two", 7808]]
Run Code Online (Sandbox Code Playgroud)
在红宝石?flatten将这一直转换为
["Club three Team one", 7303, "Club three Team two", 7304, "Club four Team one", 7310, "Club four Team two", 7311]
Run Code Online (Sandbox Code Playgroud) 我一直在尝试安装这个'rubygame'宝石一段时间,但每当我使用命令时
gem install rubygame
Run Code Online (Sandbox Code Playgroud)
它会给出一个错误:
ERROR: Could not find a valid gem 'rubygame' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)
Run Code Online (Sandbox Code Playgroud)
我也尝试了其他宝石,但结果相似:
ERROR: Could not find a valid gem 'rake' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)
Run Code Online (Sandbox Code Playgroud)
我已经确定我有互联网连接,并且已经尝试重新安装ruby和rubygems(目前使用ruby 1.8,rubygems 1.7.2).谷歌搜索根本没有帮助我.如果有人能解决我的问题,我将非常感激.我的来源列表只显示http://rubygems.org
我有一小段Ruby代码:
files.each do |file|
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp_r(file, target, :verbose => true)
end
Run Code Online (Sandbox Code Playgroud)
我想添加一个支票
if file is a folder
# do this
if file is a file
# do that
Run Code Online (Sandbox Code Playgroud)
我如何在Ruby中实现?
错误消息:
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 -r ./siteconf20150328-1540-hff2f0.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby2.1
--help
--clean
/usr/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': …Run Code Online (Sandbox Code Playgroud)