self

Use of “Self” keyword in Objective-C [duplicate]

梦想与她 提交于 2019-12-02 21:25:42
This question already has answers here : Objective-C - When to use 'self' (2 answers) Possible Duplicate: Objective-C - When to use ‘self’ I can't understand very well the importance and the usage of the "self" keyword in objective-c. It's my first OOP language so i got stuck on some concepts. When i should use "self"? Why is it useful? Thanks for the answers! Edit: I can't understand why is this a duplicated post of Objective-C - When to use 'self' when there there is not the explanation of "Self" that i wanted. self is a special variable in Objective-C, inside an instance method this

Can anybody please explain (my $self = shift) in Perl

淺唱寂寞╮ 提交于 2019-12-02 17:40:40
I'm having a really hard time understanding the intersection of OO Perl and my $self = shift; The documentation on these individual elements is great, but none of them that I've found touch on how they work together. I've been using Moose to make modules with attributes, and of course, it's useful to reference a module's attribute within said module. I've been told over and over again to use my $self = shift; within a subroutine to assign the module's attributes to that variable. This makes sense and works, but when I'm also passing arguments to the subroutine, this process clearly takes the

Rails — self vs. @

落花浮王杯 提交于 2019-12-02 16:48:40
I am following Michael Hartl's RoR tutorial, and it is covering the basics of password encryption. This is the User model as it currently stands: class User < ActiveRecord::Base attr_accessor :password attr_accessible :name, :email,: password, :password_confirmation email_regex = /^[A-Za-z0-9._+-]+@[A-Za-z0-9._-]+\.[A-Za-z0-9._-]+[A-Za-z]$/ #tests for valid email addresses. validates :name, :presence => true, :length => {:maximum => 50} validates :email, :presence => true, :format => {:with => email_regex}, :uniqueness => {:case_sensitive => false} validates :password, :presence => true,

Python- how to get list of self variables in a class consist of N-self

China☆狼群 提交于 2019-12-02 13:15:30
Edited: I want to generate N-number of agents. Each agent will have a name, so I create a random name from names and assigned it to class Agent. After I run the model, I want to get the list of my agents name. This is from mesa: import names from mesa import Agent, Model from mesa.time import RandomActivation class Agent(Agent): def __init__(self, name): self.name= names.get_full_name() self.wealth = 1 def step(self): pass class Model(Model): def __init__(self, N): self.num_agents = N self.schedule = RandomActivation(self) for i in range(N): a = MoneyAgent(i) self.schedule.add(a) def step(self

Objective-C: self = nil doesn't set instance to null value

喜欢而已 提交于 2019-12-02 11:22:14
问题 I've got the next code, pretty simple: //SecondViewController.m if(contentRvController==nil){ contentRvController = [[ContentView alloc] initWithNibName:@"ContentView" bundle:nil]; //ContentView is a custom UIViewController .... [self.view addSubview:contentRvController.view]; } else{ contentRvController.view.hide = YES; [contentRvController release]; contentRvController = nil; } Basically, when the code is launched from a button, if the UIViewController does not exist, create one and display

python self-less

爱⌒轻易说出口 提交于 2019-12-02 04:55:51
问题 this works in the desired way: class d: def __init__(self,arg): self.a = arg def p(self): print "a= ",self.a x = d(1) y = d(2) x.p() y.p() yielding a= 1 a= 2 i've tried eliminating the "self"s and using a global statement in __init__ class d: def __init__(self,arg): global a a = arg def p(self): print "a= ",a x = d(1) y = d(2) x.p() y.p() yielding, undesirably: a= 2 a= 2 is there a way to write it without having to use "self"? 回答1: Python methods are just functions that are bound to the class

python self-less

*爱你&永不变心* 提交于 2019-12-02 01:43:46
this works in the desired way: class d: def __init__(self,arg): self.a = arg def p(self): print "a= ",self.a x = d(1) y = d(2) x.p() y.p() yielding a= 1 a= 2 i've tried eliminating the "self"s and using a global statement in __init__ class d: def __init__(self,arg): global a a = arg def p(self): print "a= ",a x = d(1) y = d(2) x.p() y.p() yielding, undesirably: a= 2 a= 2 is there a way to write it without having to use "self"? Python methods are just functions that are bound to the class or instance of a class. The only difference is that a method (aka bound function) expects the instance

Python class methods changing self

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 23:48:31
This isn't for anything I'm working on yet, it's just some test code as I'm just learning class methods and suck. But say I have the following code class Test(int): def __init__(self,arg): self = arg def thing(self): self += 10 and going, foo=Test(12) sets foo to 12. However I want it, so when I do, foo.thing(), foo increases by 10. So far, going foo.thing() just keeps it at 12. How would I change this code to do that. Because int is a immutable, you cannot magically turn it into a mutable type. Your methods are no-ops. They change self in the local namespace, by reassigning it to something

Python, __init__ and self confusion

拜拜、爱过 提交于 2019-12-01 20:49:23
Alright, so I was taking a look at some source when I came across this: >>> def __parse(self, filename): ... "parse ID3v1.0 tags from MP3 file" ... self.clear() ... try: ... fsock = open(filename, "rb", 0) ... try: ... fsock.seek(-128, 2) ... tagdata = fsock.read(128) ... finally: ... fsock.close() ... if tagdata[:3] == 'TAG': ... for tag, (start, end, parseFunc) in self.tagDataMap.items(): ... self[tag] = parseFunc(tagdata[start:end]) ... except IOError: ... pass ... So, I decided to test it out. >>> __parse("blah.mp3") And, I received this error: Traceback (most recent call last): File "

What does self mean in Ruby? [duplicate]

余生长醉 提交于 2019-12-01 14:54:13
This question already has an answer here: Ruby Definition of Self 3 answers What does ruby self represent? what is it? what does it mean? Could some please explain it to me? in simple terms please And what is its function in a class? class MyClass def method.self end end self refers to the object that is currently in context. In your example, self is the class itself and def self.method is defining a class method. For example: class MyClass def self.method puts "Hello!" end end > MyClass.method #=> "Hello" You can also use self on instances of a class. class MyClass def method_a puts "Hello!"