2011-10-28 75 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.单击为您更改的九个类别中的每一个应用
相关问题