Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Methods ruby语言中函数(方法)后的ruby空间_Methods_Expression_Space_Between - Fatal编程技术网

Methods ruby语言中函数(方法)后的ruby空间

Methods ruby语言中函数(方法)后的ruby空间,methods,expression,space,between,Methods,Expression,Space,Between,为什么把“你好世界”置为零?在ruby语言中,puts(“hello world”)是不同的。nil 以上句子的区别在于空格。 放(“你好世界”)。零?和put(“hello world”).nil?如果使用put(“hello world”).nil?,ruby会认为这些函数调用: $ ruby -rripper -rpp -e 'pp Ripper.sexp("puts(hello world).nil?")' [:program, [[:call, [:method_add_arg

为什么把“你好世界”置为零?在ruby语言中,puts(“hello world”)是不同的。nil

以上句子的区别在于空格。 放(“你好世界”)。零?和put(“hello world”).nil?

如果使用
put(“hello world”).nil?
ruby
会认为这些函数调用:

$ ruby -rripper -rpp -e 'pp Ripper.sexp("puts(hello world).nil?")'
[:program,
 [[:call,
   [:method_add_arg,
    [:fcall, [:@ident, "puts", [1, 0]]],
    [:arg_paren,
     [[:command,
       [:@ident, "hello", [1, 5]],
       [:args_add_block, [[:vcall, [:@ident, "world", [1, 11]]]], false]]]]],
   :".",
   [:@ident, "nil?", [1, 18]]]]]
在这种情况下,括号是arg\u paren

如果使用
put(“hello world”).nil?
ruby
会将括号视为传递给
put的参数的一部分:

$ ruby -rripper -rpp -e 'pp Ripper.sexp("puts (hello world).nil?")'
[:program,
 [[:command,
   [:@ident, "puts", [1, 0]],
   [:args_add_block,
    [[:call,
      [:paren,
       [:command,
        [:@ident, "hello", [1, 6]],
        [:args_add_block, [[:vcall, [:@ident, "world", [1, 12]]]], false]]],
      :".",
      [:@ident, "nil?", [1, 19]]]],
    false]]]]
在这种情况下,括号是paren