instance-variables

    1熱度

    1回答

    所以我正在用Python編寫一個程序,而且它變得相當長。正如我擴展它,我已經開始注意到,我的一些類獲得了很多屬性,並且我將它們傳遞給__init__的方式只是感覺不太理想。作爲一個例子,這裏是我在說什麼: class Enemy(Ship): def __init__(self,m=20000,size=32,F=[0,0],X=[0,0],v=[0,0],a=[0,0],p=[0,0],

    0熱度

    1回答

    假設我有以下幾點: module MyModule module SubModule Var = 'this is a constant' var = 'this is not a constant' def hello_world return 'hello world!' end end end 在同一個文件,我只能

    -1熱度

    1回答

    我的代碼中的一個實例變量不斷地重新賦值,儘管沒有命令可以這樣做。實質上,變量只能被調用兩次:一次,在啓動時賦值,然後將其值複製到另一個變量。我工作的代碼是有點複雜,我在這裏完全發佈,但是,這個是它的一個基本的破敗: class Test def self.initialize @problem_var = [ ["1 2 3", "4 5 6"], ["a b c", "d

    2熱度

    3回答

    什麼會導致我的實例變量@product未被設置/傳遞給重定向。 Product是一個ActiveModel對象,不是ActiveRecord。更具體地說,@ product變量不會出現在redirect_to(new_services_path)或redirect_to(home_path)頁面中。由於@product變量需要在每頁上的頁腳中填充表單。 Application_controller

    0熱度

    1回答

    我對編程知道的一切都表示,實例方法可以調用類方法,但類方法不能調用實例方法。 這個帖子同意... Call instance method from class method 然而,奇蹟般地類方法sharedInstance設法調用實例方法init。我在想什麼? static iRpDatabase *sharedDatabase; @implementation iRpDatabase {

    0熱度

    1回答

    我有一個類MicController,並給它一個這樣的實例變量: @implementation MicController { AudioStreamBasicDescription streamFormat; } 我初始化對象並嘗試使用創建音頻單元該ASBD變量用於跟蹤流格式。 - (instancetype)init { if (self = [super init

    2熱度

    1回答

    我試圖找到一種方法來掃描BLE設備並將它們呈現在UITableView中。 BLE設備的掃描,連接,讀取和寫入功能非常明確,並且很有用!所以我的問題集中在'ScanTableView'和'BletoothManager'類之間的交互。 這些是我的兩個類: // ScanTableView.swift import UIKit class ScanTableView: UITableView

    0熱度

    2回答

    我得不到的是, 我知道自動屬性是想讓事情變得更容易。 通常情況下: private string name; public string Name { get { return name; } set { name = value; } } 隨着自動屬性: public string Name { get; set; } 但是,如果我們可以只聲明實例變量爲pub

    -1熱度

    1回答

    我想有一個用戶類,如下 class User def initialize test end def test name = ['name1','name2', 'name3'] returned_value = test1(name) lots of if else condition based on returned_v

    0熱度

    2回答

    我正在閱讀一篇文章並且遇到了第一個示例代碼。在模型中,實例變量被設置爲避免不必要的查詢。我還在其中一個欄目中看到了這一點(第二個例子)。另一方面,我讀了更多的文章,如果我使用這種模式,那麼我的應用程序可能不會線程安全,所以我不能利用我的彪馬網絡服務器。 可以告訴我何時何地我應該使用這種模式? 1日例如: def first_order_date if first_order f