Ubuntu 11.
我做以下事情:
$ rvm --default use 1.9.2
我得到:
Using /home/md/.rvm/gems/ruby-1.9.2-p180
这样很好.
但是当我现在打开一个新的终端窗口时,我仍然得到:
$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
因此Module可以在Ruby中使用除了mixins之外还提供命名空间,如下所示:
module SomeNamespace
class Animal
end
end
animal = SomeNamespace::Animal.new
Run Code Online (Sandbox Code Playgroud)
但我也看到过以下用途:
module SomeNamespace
end
class SomeNamespace::Animal
end
animal = SomeNamespace::Animal.new
Run Code Online (Sandbox Code Playgroud)
我的问题是它们是如何不同的(如果它们是),哪个是更惯用的Ruby?
我是python的新手,我打算学习django.我有一些ruby(而不是rails)的经验,我熟悉RVM但是我不明白pythonbrew和virtualenv之间的区别.我知道pythonbrew是RVM的模仿,但我认为virtualenv已经在做RVM所做的事情(反之亦然,pythonbrew已经在做RVM的工作).有人可以解释一下,或许可以提供一些具体的例子/用法来帮助我理解它.非常感谢!
我有这个form_for:
<%= form_for [post, Comment.new,], :remote => true do |f| %>
<%= f.text_area :content, :cols =>10, :rows => 1%>
<% end %>
<%= f.submit :class => "input_comment" %>
Run Code Online (Sandbox Code Playgroud)
那会生成下一个代码html:
<form method="post" id="new_comment" data-remote="true" class="new_comment"
action="/post/4efcda9e1d41c82486000077/comments" accept-charset="UTF-8"><div
style="margin:0;padding:0;display:inline"><input type="hidden" value="?" name="utf8">
<input type="hidden" value="ctVfDF/O4FIR91I7bC5MVezQmutOCkX3dcXe73uNPZY=" name="authenticity_token">
<textarea rows="1" name="comment[content]" id="comment_content" cols="10"></textarea>
<input type="submit" value="Create Comment" name="commit" class="input_comment">
</form>
Run Code Online (Sandbox Code Playgroud)
如果我在同一页面中有多个表单,则不是具有相同ID的html有效.
在同一页面中有这么多表单是无效的HTML.
如何通过rails 3.1中的form_for方法助手更改id autogenerate?
我看了这个视频.为什么a = a评估nil是否a未定义?
a = a # => nil
b = c = q = c # => nil
Run Code Online (Sandbox Code Playgroud) 我是红宝石的新手.希望知道如何在ruby中编写以下循环.
for (i = 25; i >= 0; i--) {
print i;
}
Run Code Online (Sandbox Code Playgroud) 我在许多ruby脚本中看到了很多,但不确定它意味着什么:
$:.unshift File.dirname(__FILE__)
Run Code Online (Sandbox Code Playgroud) 如何在Ruby中的字符串的两个字符串标记之间返回字符串?
例如,我有:
input_string str1_markerstringstr2_markerstring想做类似的事情:
input_string.string_between_markers(str1_markerstring, str2_markerString)
Run Code Online (Sandbox Code Playgroud)
示例文字:
s
# => "Charges for the period 2012-01-28 00:00:00 to 2012-02-27 23:59:59:<br>\nAny Network Cap remaining: $366.550<br>International Cap remaining: $0.000"
str1_markerstring
# => "Charges for the period"
str2_markerstring
# => "Any Network Cap"
s[/#{str1_markerstring}(.*?)#{str2_markerstring}/, 1]
# => nil # IE DIDN'T WORK IN THIS CASE
Run Code Online (Sandbox Code Playgroud) Ruby中获取第一个可枚举元素的最快方法是什么?
例如:
arr = [12, 88, 107, 500]
arr.select {|num| num > 100 }.first # => 107
Run Code Online (Sandbox Code Playgroud)
我想这样做而不会遍历整个阵列select,因为我只需要第一场比赛.
我知道我可以做一个each并且取决于成功,但我认为有一种本地方法可以做到这一点; 我只是没有在文档中找到它.
ruby ×10
rvm ×2
arrays ×1
comparison ×1
enumerable ×1
form-for ×1
loops ×1
python ×1
pythonbrew ×1
regex ×1
ruby-1.9.2 ×1
scala ×1
virtualenv ×1