Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
Ruby 将进程存储在散列中的数组中_Ruby_Arrays_Hash_Proc - Fatal编程技术网

Ruby 将进程存储在散列中的数组中

Ruby 将进程存储在散列中的数组中,ruby,arrays,hash,proc,Ruby,Arrays,Hash,Proc,我还在写我的文字冒险。我的使用/功能有问题。这意味着调用一个散列,其中键是使用过的对象,内容包括一个数组;数组中的第一个元素是目标对象,第二个元素是Proc,如果该关系与use/with函数的参数匹配,则将执行该Proc 请澄清我如何在散列中的数组中存储代码块,以便稍后根据组合的对象调用它 这是我的使用函数,它采用“使用对象”和“使用对象”: 这就是我定义关系的方式(到目前为止只有一个): 每当我打字的时候 use key with clock 它只返回一个新的提示行。您忘记了。调用程序: I

我还在写我的文字冒险。我的使用/功能有问题。这意味着调用一个散列,其中键是使用过的对象,内容包括一个数组;数组中的第一个元素是目标对象,第二个元素是Proc,如果该关系与use/with函数的参数匹配,则将执行该Proc

请澄清我如何在散列中的数组中存储代码块,以便稍后根据组合的对象调用它

这是我的使用函数,它采用“使用对象”和“使用对象”:

这就是我定义关系的方式(到目前为止只有一个):

每当我打字的时候

use key with clock

它只返回一个新的提示行。

您忘记了
。调用
程序:

INTERACTIONS = {"key" => ["clock", Proc.new {puts "You open the clock!"}]}

def use(object, with)
  if INTERACTIONS[object][0] == with
    INTERACTIONS[object][1].call  # procs need to be `call`ed :)
  end
end


use("key", "clock") # => You open the clock!
use key with clock
INTERACTIONS = {"key" => ["clock", Proc.new {puts "You open the clock!"}]}

def use(object, with)
  if INTERACTIONS[object][0] == with
    INTERACTIONS[object][1].call  # procs need to be `call`ed :)
  end
end


use("key", "clock") # => You open the clock!