简体   繁体   English

我如何将一个类的实例变量访问到另一个类中的ruby中的其他文件中定义

[英]how do i access instance variable of one class into other class define in other file in ruby

I have one file named class1.rb this is structure 我有一个名为class1.rb的文件,这是结构

module Person
  class Amit
    def initialize
      @a=10
    end
  end 
end

another file named class2.rb 另一个名为class2.rb的文件

module Person 
  class Sumit < Amit
    def aos
      puts "#{@a}"
    end
  end
end

i am not able to acess variable @a in Sumit how do i do that?? 我无法在Sumit访问变量@a ,我该怎么做?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何访问相同类的其他对象的实例变量 - How to access instance variable of other object of same class 如何在 Ruby 的同一 class 中使用从一种方法到另一种方法的变量? - How to use a variable from one method to other in a same class in Ruby? 如何使用 ruby 提取和排序一个 class 的实例变量,这些变量存储在另一个 class 的实例变量内部的数组中? - How do I extract and sort the instance variables of one class, that are stored in an array inside of an instance variable in another class using ruby? 我可以在Ruby中定义对其他作用域隐藏的类吗? - Can I define a class in Ruby that is hidden to other scopes? 我应该如何在Ruby中定义其处理算法在超类中定义的实例变量? - How should I define an instance variable in Ruby whose processing algorithm is defined in a super class? 在自定义Ruby类中,如何定义实例的默认表示形式? - In a custom Ruby class, how do you define the default representation of an instance? 如何初始化Ruby中当前类以外的实例? - How to initialise an instance other than the current class in Ruby? Ruby:定义一个 class,它在没有任何方法调用实例时返回除自身之外的其他内容 - Ruby: define a class that returns something other than itself when an instance is called without any methods 如何在实例中访问类变量? - How can I access class variable in an instance? 无法在Ruby中的类之外访问实例变量 - Unable to access instance variable outside the class in ruby
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM