From f6bdcef37605f468e288340c5f6c0ee5ec7faa7d Mon Sep 17 00:00:00 2001 From: Nakilon Date: Fri, 16 May 2014 10:38:50 +0400 Subject: [PATCH] functional solution for method_name --- lib/robjc/resources/string_resource.rb | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/robjc/resources/string_resource.rb b/lib/robjc/resources/string_resource.rb index ea14b1c..f691d7d 100644 --- a/lib/robjc/resources/string_resource.rb +++ b/lib/robjc/resources/string_resource.rb @@ -9,18 +9,9 @@ def strings @strings ||= read_strings_file end - def method_name(string) - components = string.split('_') - string = components.first.downcase - if components.length == 1 - string - else - components.each_with_index do |s, i| - next if i == 0 - string += s.capitalize - end - end - string + def method_name string + components = string.split "_" + [components.shift.downcase, *components.map(&:capitalize)].join end private