ruby-2.2

Keyword arguments unpacking (splat) in Ruby

限于喜欢 提交于 2019-11-28 02:54:04
问题 What is happening below seems a little strange to me. def f(a, b) puts "#{a} :: #{b}" end f(*[1, 2], **{}) # prints "1 :: 2" hash = {} f(*[1, 2], **hash) ArgumentError: wrong number of arguments (3 for 2) f(*[1, 2], **Hash.new) ArgumentError: wrong number of arguments (3 for 2) Is this a compiler optimization feature? 回答1: That is a Ruby's bug that has been reported several times (for example here by me) but has not been fixed. I guess that since the keyword argument feature has been

Why doesn't Ruby find classes in a higher scope when module is specified using ::?

对着背影说爱祢 提交于 2019-11-28 00:15:17
I just got stuck on this for a while. Take this base: module Top class Test end module Foo end end Later, I can define classes inside Foo that extends Test by doing this: module Top module Foo class SomeTest < Test end end end However, if I try to minimize indentation by using :: to specify the module: module Top::Foo class Failure < Test end end This fails with: NameError: uninitialized constant Top::Foo::Test Is this a bug, or is it just a logical consequence of the way Ruby resolves variable names? Is this a bug, or is it just a logical consequence It's a "quirk". Some consider it a bug.

rails server cannot start; getaddrinfo: nodename nor servname provided, or not known (SocketError)

坚强是说给别人听的谎言 提交于 2019-11-27 16:57:17
问题 I have not found a solution to the problem, however someone did already ask about the same problem a few days ago - (Rails Server Keeps Exiting (SocketError)) After I start a rails server the system returns some error I cannot understand. To install Ruby on Rails on my mac I did everything as listed on http://railsapps.github.io/installrubyonrails-mac.html here is my terminal response: $ rails server => Booting WEBrick => Rails 4.2.0 application starting in development on http://localhost

Why doesn't Ruby find classes in a higher scope when module is specified using ::?

≡放荡痞女 提交于 2019-11-26 21:40:01
问题 I just got stuck on this for a while. Take this base: module Top class Test end module Foo end end Later, I can define classes inside Foo that extends Test by doing this: module Top module Foo class SomeTest < Test end end end However, if I try to minimize indentation by using :: to specify the module: module Top::Foo class Failure < Test end end This fails with: NameError: uninitialized constant Top::Foo::Test Is this a bug, or is it just a logical consequence of the way Ruby resolves