我如何知道在github上分配了我的回购(How can I tell who forked my repository on GitHub?)
有没有办法知道谁在GitHub上分配了我的回购 我可以看到叉子的数量,但是我也想知道谁分配了我的回购,还有什么样的改变。 我知道如果他们有兴趣回馈给我的回购,他们可以给我一个拉动请求,有没有其他方法可以找出我们的所有人分了我的回购?
Is there a way to know who has forked my repository on GitHub? I can see the number of forks, but I'd like to know who forked my repository and what kind of changes they made to it.
I know they can send me a pull request if they're interested in contributing back to my repository, but is there some other way for me to find out who forked my repository?
原文:https://stackoverflow.com/questions/12208450
最满意答案
是的,你可以这样使用
instance_variable_get
:class Hello def method1 @hello = "pavan" end end h = Hello.new p h.instance_variable_get(:@hello) #nil p h.method1 #"pavan" - initialization of @hello p h.instance_variable_get(:@hello) #"pavan"
如果变量未定义(在我的示例中首先调用
instance_variable_get
),则nil
。
安德烈在他的评论中提到:
您不应该将其作为默认方式访问实例变量,因为它违反封装。
更好的方法是定义一个访问器:
class Hello def method1 @hello = "pavan" end attr_reader :hello end h = Hello.new p h.hello #nil p h.method1 #"pavan" - initialization of @hello p h.hello #"pavan"
如果您想要另一个方法名称,可以将访问器
alias :my_hello :hello
。并且如果类没有在您的代码中定义,而是在一个gem中:您可以修改代码中的类并将新的函数插入到类中 。
Yes, you can use
instance_variable_get
like this:class Hello def method1 @hello = "pavan" end end h = Hello.new p h.instance_variable_get(:@hello) #nil p h.method1 #"pavan" - initialization of @hello p h.instance_variable_get(:@hello) #"pavan"
If the variable is undefined (first call of
instance_variable_get
in my example) you getnil
.
As Andrew mention in his comment:
You should not make this the default way you access instance variables as it violates encapsulation.
A better way is to define an accessor:
class Hello def method1 @hello = "pavan" end attr_reader :hello end h = Hello.new p h.hello #nil p h.method1 #"pavan" - initialization of @hello p h.hello #"pavan"
If you want another method name, you could alias the accessor:
alias :my_hello :hello
.And if the class is not defined in your code, but in a gem: You can modify classes in your code and insert new functions to classes.
相关问答
更多-
是的,你可以这样使用instance_variable_get : class Hello def method1 @hello = "pavan" end end h = Hello.new p h.instance_variable_get(:@hello) #nil p h.method1 #"pavan" - initialization of @hello p h.instance_variable_get(:@hello) #"pa ...
-
您正在访问已在堆栈中分配的块,该块不再在范围内。 您需要将bb分配给复制的块。 应该将bb移动到类的实例变量中。 //Do not forget to Block_release and nil bb on viewDidUnload bb = Block_copy(bb); You are accessing the block which was allocated on the stack which is no longer in scope. You need to assign bb to t ...
-
是否有可能通过类方法访问实例方法和变量(is it possible to access instance methods and variable via class methods)[2024-02-28]
这意味着这是允许的: public class Test { public int instanceVariable = 42; public void instanceMethod() {System.out.println("Hello!");} public static void staticMethod() { Test test = new Test(); System.out.println(test.instanceVariable ... -
Ruby中的实例变量访问(Instance variable access in Ruby)[2022-06-30]
在当前代码中,您将在Test 类上定义实例变量,而不是在Test的实例上定义。 也就是说,您可以使用类方法访问它: class Test @state = 4 def self.state @state end end # Test.state # => 4 但这不是你想要的; 你不希望这个值存在于你的类中,你希望它存在于你的类的每个实例中。 要在类的实例上初始化实例变量,您应该提供一个构造函数: class Test attr_accessor :state def i ... -
使用您编辑过的MCVE: 在get_val方法中设置self.MCVE = classA()时,您将MCVE设置为classA的新实例 。 因此,对classA的某个其他实例的row_num属性的任何修改都是无关紧要的。 例如, classA().define()正在为完全不同的类实例修改row_num属性。 它的row_num是一个实例变量,仅为该特定实例定义。 如果您希望row_num属性在所有classA实例中保持classA ,您可能希望将其设置为类变量,就像这样(尽管是一个无意义的例子)。 cla ...
-
Ruby实例变量访问(Ruby instance variable access)[2023-12-08]
Getter方法,因为它更容易重构。 假设您要在访问时更新时间戳。 class Test def user @user.last_read = Time.now @user end end 并且所有对user的引用都使用新逻辑进行更新。 如果你的参考是@user , @user不那么容易了。 Getter method, because it's easier to refactor. Say you want to update a time stamp at the point ... -
为了评估局部变量,您需要传入字符串“local_var”,它将返回局部变量的值。 根据我对文档的解释,如果传入一个块,则无法传入参数。 块形式中实例eval的行为是作为闭包访问该调用所在的对象的实例变量和私有方法。 带参数的实例eval的行为允许您评估该调用范围内的字符串。 After some search and advices from my friend i think i figured out the problem. In ruby there is two Context when your ...
-
您可能能够做的最接近的事情是使用单例实例变量上的ThreadStatic属性。 这将在访问方面保持静态语义,但每个线程都有自己的实例。 public class ThreadStaticSingleton { [ThreadStatic] private static ThreadStaticSingleton instance; public static ThreadStaticSingleTon Instance { get { ...
-
你可以使用“super”来调用父类初始化块并定义实例变量“@var”。 在这种情况下,您可以为另一个实例修改此实例变量的值。 喜欢这个: class Shape def initialize () @var = "woohoo" end end class Rectangle < Shape def initialize(l, w) @length = l @width = w super() end def area() print @var ...
-
我不认为你可以用当前的代码。 您的jQuery ajax超出了上下文范围,也就是说,您从客户端触发ajax,并且服务器使用=> format.json {render :json => @markers}返回一些数据,因此从服务器返回的数据将可供您使用在你完成回调就像你已经完成。 你可以做两件事 从可以访问实例变量的操作中渲染部分内容 def index # Logic here render :partial => "locations/location_results" end 或者您可以为 ...