instance-variables

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 tkinter passing variables between functions

馋奶兔 提交于 2019-12-02 12:22:55
I am trying to pass the variable dirpath into the export_data() function. Export data runs off of a double click on a button located on a widget. Why is dirpath printing as: `<Tkinter.Event instance at 0x8ade56c>` instead of the actual path? def export_data(dirpath): print 'exporting...' print str(dirpath) os.mkdir('/home/bigl/Desktop/Library') shutil.copytree(dirpath, output_path) When I run my code I get the error exporting... <Tkinter.Event instance at 0x8ade56c> Traceback (most recent call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__ return self.func(*args)

Class Variable behaving like Instance Variable (Python 3.4)

江枫思渺然 提交于 2019-12-02 08:54:52
问题 Python 3.4.0a1 Windows 8.1 Class Created: class Bank(object): bankrupt = False Command entered in IDLE __main__ with the following results: >>> a = Bank() >>> b = Bank() >>> a.bankrupt False >>> b.bankrupt False >>> b.bankrupt = True >>> b.bankrupt True >>> a.bankrupt False Expected output: I expected a.bankrupt to change to True when I changed b.bankrupt since the variable bankrupt is defined for the entire class and not for a single instance (with self.bankrupt ) Why is this not happening?

What is the difference between Object b(); and Object b;?

懵懂的女人 提交于 2019-12-02 07:11:48
问题 To be more explicit, I get a compile time error when I try accessing an instance variable when I create an object using (), but when I don't, the code compiles and runs as expected. Also, this problem only applies to the default constructor. I would like to understand why. using namespace std; #include <iostream> class Student { public: int gpa; Student() { gpa = 4; } Student( int x ) { gpa = x; } }; int main() { Student zero; Student sally( 2 ); Student jack(); cout << zero.gpa << endl; /

How to fix - 41: non-static variable cannot be referenced from a static context -> What is the reason for this?

馋奶兔 提交于 2019-12-02 06:51:24
I'm trying to write this code to get the first initialCapacity prime numbers and then print them in sequence using java. It isn't working for two reasons, firstly I get the error 41: non-static variable listOfPrimeNumbers cannot be referenced from a static context when I try to run the program, but even when I change the variable to static and run the program, it will only print out "1". So it is only iterating the while loop in the constructor Primes once, and then stopping and I simply cannot find the problem there no matter how hard I look ! Would anyone be able to help me out please, even

Class Variable behaving like Instance Variable (Python 3.4)

你。 提交于 2019-12-02 06:20:16
Python 3.4.0a1 Windows 8.1 Class Created: class Bank(object): bankrupt = False Command entered in IDLE __main__ with the following results: >>> a = Bank() >>> b = Bank() >>> a.bankrupt False >>> b.bankrupt False >>> b.bankrupt = True >>> b.bankrupt True >>> a.bankrupt False Expected output: I expected a.bankrupt to change to True when I changed b.bankrupt since the variable bankrupt is defined for the entire class and not for a single instance (with self.bankrupt ) Why is this not happening? You assigned to a new attribute to the instance instead. To change a class attribute, assign directly

Scan for BLE devices and present them in an UITableView

做~自己de王妃 提交于 2019-12-02 05:51:14
问题 I try to find a way to scan for BLE devices and present them in an UITableView. The scan, connect, read and write functionality for BLE devices is clear and works! So my questions are focused on the interaction between the 'ScanTableView' and 'BletoothManager' class. These are my two classes: // ScanTableView.swift import UIKit class ScanTableView: UITableViewController { @IBOutlet var scanTableView: UITableView! var bluetoothManager = BluetoothManager?() var tableViewScanTime = 5 var timer1:

What is the difference between Object b(); and Object b;?

烈酒焚心 提交于 2019-12-02 04:33:48
To be more explicit, I get a compile time error when I try accessing an instance variable when I create an object using (), but when I don't, the code compiles and runs as expected. Also, this problem only applies to the default constructor. I would like to understand why. using namespace std; #include <iostream> class Student { public: int gpa; Student() { gpa = 4; } Student( int x ) { gpa = x; } }; int main() { Student zero; Student sally( 2 ); Student jack(); cout << zero.gpa << endl; //prints 4 cout << sally.gpa << endl; // prints 2 cout << jack.gpa << endl; //error: request for member

Should Equality Comparison of Float / Double Instance Variables in an Equals Method be Exact?

断了今生、忘了曾经 提交于 2019-12-02 04:12:18
问题 I'm overriding an equality method for an object. Let's say an odometer with a km variable stored as a double (along with some other variables not important for the example). public class Odometer { private double km; @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(km); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj ==

Instance variable not retaining value in iOS application

て烟熏妆下的殇ゞ 提交于 2019-12-02 04:07:16
I have declared this ivar in my ViewController.h #import <UIKit/UIKit.h> @interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { NSArray *sortedCountries; } @property (nonatomic, retain) NSArray *sortedCountries; @end In ViewController.m, sortedCountries does it's job in -(void)ViewDidLoad{} by storing the result of a sorted .plist. When -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} is called below, sortedCountries returns (null) Why doesn't the value of sortedCountries remain? I added a retain