Ruby GTK3移行後のメインリポジトリ
Revision | 2e0724aabae74c1570e6013373b2b99e8250060a (tree) |
---|---|
Time | 2016-12-11 14:43:42 |
Author | Shyouzou Sugitani <shy@user...> |
Commiter | Shyouzou Sugitani |
coding style cleanup
@@ -18,16 +18,18 @@ module Alias | ||
18 | 18 | |
19 | 19 | def self.fatal(error) |
20 | 20 | Logging::Logging.error('alias.rb: ' + error.to_s) |
21 | - NConfig.null_config() | |
21 | + NConfig.null_config | |
22 | 22 | end |
23 | 23 | |
24 | 24 | def self.create_from_file(path) |
25 | - f = File.open(path, 'rb') | |
26 | 25 | buf = [] |
27 | - while line = f.gets | |
28 | - buf << line.strip unless line.strip.empty? | |
29 | - end | |
30 | - return create_from_buffer(buf) | |
26 | + File::open(path, 'rb') {|f| | |
27 | + while line = f.gets | |
28 | + line = line.strip | |
29 | + buf << line unless line.empty? | |
30 | + end | |
31 | + } | |
32 | + create_from_buffer(buf) | |
31 | 33 | end |
32 | 34 | |
33 | 35 | def self.create_from_buffer(buf) |
@@ -39,7 +41,7 @@ module Alias | ||
39 | 41 | i += 1 |
40 | 42 | next if line.length.zero? |
41 | 43 | match = re_alias.match(line) |
42 | - if not match.nil? | |
44 | + unless match.nil? | |
43 | 45 | name = line |
44 | 46 | table = {} |
45 | 47 | begin |
@@ -110,6 +112,6 @@ module Alias | ||
110 | 112 | dic[key] = value |
111 | 113 | end |
112 | 114 | end |
113 | - return dic | |
115 | + dic | |
114 | 116 | end |
115 | 117 | end |
@@ -32,7 +32,7 @@ module Communicate | ||
32 | 32 | end |
33 | 33 | |
34 | 34 | def notify_all(event, references) |
35 | - for sakura in @ghosts.keys() | |
35 | + @ghosts.each_key do |sakura| | |
36 | 36 | sakura.enqueue_event(event, *references) |
37 | 37 | end |
38 | 38 | end |
@@ -52,9 +52,7 @@ module Communicate | ||
52 | 52 | event, name, selfname, shell_name, |
53 | 53 | flag_break, communicate, |
54 | 54 | sstp, notranslate, script, references) |
55 | - if script.empty? and not ON_OTHER_EVENT.include?(event) | |
56 | - return | |
57 | - end | |
55 | + return if script.empty? and not ON_OTHER_EVENT.include?(event) | |
58 | 56 | on_other_event = nil |
59 | 57 | if ON_OTHER_EVENT.include?(event) |
60 | 58 | if flag_break and ['OnClose', 'OnVanishSelected'].include?(event) |
@@ -25,26 +25,21 @@ module NConfig | ||
25 | 25 | end |
26 | 26 | |
27 | 27 | def self.create_from_file(path) |
28 | - charset = 'CP932' # default | |
29 | - f = File.open(path, 'rb') | |
30 | - if f.read(3).bytes == [239, 187, 191] # "\xEF\xBB\xBF" | |
31 | - f.close | |
32 | - f = File.open(path, 'rb:BOM|UTF-8') | |
33 | - charset = 'UTF-8' | |
34 | - else | |
35 | - f.seek(0) # rewind | |
36 | - end | |
28 | + has_bom = File.open(path) {|f| f.read(3) } == "\xEF\xBB\xBF" | |
29 | + charset = has_bom ? 'UTF-8' : 'CP932' | |
37 | 30 | buf = [] |
38 | - while line = f.gets | |
39 | - buf << line.strip unless line.strip.empty? | |
40 | - end | |
41 | - f.close | |
31 | + File.open(path, has_bom ? 'rb:BOM|UTF-8' : 'rb') {|f| | |
32 | + while line = f.gets | |
33 | + line = line.strip | |
34 | + buf << line unless line.empty? | |
35 | + end | |
36 | + } | |
42 | 37 | return create_from_buffer(buf, :charset => charset) |
43 | 38 | end |
44 | 39 | |
45 | 40 | def self.create_from_buffer(buf, charset: 'CP932') |
46 | 41 | dic = Config.new |
47 | - for line in buf | |
42 | + buf.each do |line| | |
48 | 43 | line = line.force_encoding(charset).encode( |
49 | 44 | "UTF-8", :invalid => :replace, :undef => :replace) |
50 | 45 | key, value = line.split(",", 2) |
@@ -68,6 +63,6 @@ module NConfig | ||
68 | 63 | end |
69 | 64 | |
70 | 65 | def self.null_config() |
71 | - NConfig::Config.new() | |
66 | + NConfig::Config.new | |
72 | 67 | end |
73 | 68 | end |
@@ -22,18 +22,18 @@ module Textcopy | ||
22 | 22 | class Saori < DLL::SAORI |
23 | 23 | |
24 | 24 | def initialize |
25 | - super() | |
25 | + super | |
26 | 26 | @clipboard = nil |
27 | 27 | end |
28 | 28 | |
29 | 29 | def setup |
30 | 30 | @clipboard = Gtk::Clipboard.get('PRIMARY') |
31 | - return 1 | |
31 | + 1 | |
32 | 32 | end |
33 | 33 | |
34 | 34 | def finalize |
35 | 35 | @clipboard = nil |
36 | - return 1 | |
36 | + 1 | |
37 | 37 | end |
38 | 38 | |
39 | 39 | def execute(argument) |
@@ -51,7 +51,7 @@ module Yaya | ||
51 | 51 | result = 105 |
52 | 52 | end |
53 | 53 | end |
54 | - return result | |
54 | + result | |
55 | 55 | end |
56 | 56 | |
57 | 57 | def show_description |
@@ -76,8 +76,7 @@ module Yaya | ||
76 | 76 | ) |
77 | 77 | path[0, @dir.bytesize] = @dir |
78 | 78 | @id = $_yaya.multi_load(path, @dir.bytesize) |
79 | - ret = 1 | |
80 | - return ret | |
79 | + 1 | |
81 | 80 | end |
82 | 81 | |
83 | 82 | def unload |
@@ -95,7 +94,7 @@ module Yaya | ||
95 | 94 | rlen =[req_string.bytesize].pack("l!") |
96 | 95 | ret = $_yaya.multi_request(@id, request, rlen) |
97 | 96 | rlen, = rlen.unpack("l!") |
98 | - return ret[0, rlen].to_s | |
97 | + ret[0, rlen].to_s | |
99 | 98 | end |
100 | 99 | end |
101 | 100 | end |