2011-10-28 77 views
8

我使用的RubyMine它告訴我,ruby​​中方法名稱的最大長度是多少?

unsubscribe_from_all_notifications 

...是一個方法名稱太長。最大長度是多少?

+4

我猜這是一個RubyMine問題;我嘗試了一個名爲'unsubscribe_from_all_notifications_and_keep_making_this_bloody_thing_longer_and_longer_and_longer_and_longer_and_longer'的方法,它在Ruby 1.8.7和1.9.2中工作得很好...... – BaronVonBraun

+0

對任何人進行元編程? –

+0

@AndrewGrimm完成:-) –

回答

13

RubyMine謊言:-)或者至少並不意味着它是Ruby解釋器的限制。

looong_name = "a" * 10000; # => "aaaaaaaaa..... 
a_class = Class.new 
a_class.__send__(:define_method, looong_name) { :hello } 
a_class.new.__send__(looong_name) # => :hello 

puts a_class.instance_methods.inspect # you better not run this :-) 
1

AFAIK在ruby中沒有方法名的大小限制。

很可能你在RubyMine中有一些編碼風格設置,它會向你顯示這個警告。如果在Mac上檢查RubyMine>首選項>代碼樣式> Ruby並查看是否有某種偏好。

只是爲了讓你知道我也使用RubyMine,但我沒有看到爲我設置的這種編碼風格。

14

的RubyMine,您可以更改的最大長度由紅寶石名稱的所有類別:

  1. 選擇菜單項的RubyMine - >
  2. 在結果在編輯,選擇檢查下左窗格中的模態對話框。
  3. 在右側的結果窗格中,選擇紅寶石命名約定
  4. 您需要更改九個類別的Ruby名稱。每個顯示編輯字段爲最大長度。因此,例如,我將它們全部從20或30更改爲60.單擊爲您更改的九個類別中的每一個應用
相關問題