File tree Expand file tree Collapse file tree 4 files changed +9
-28
lines changed Expand file tree Collapse file tree 4 files changed +9
-28
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
7
7
## [ Unreleased]
8
8
### Added
9
-
10
9
- Provide an ` itoa ` function. It is present in Arduino's runtime environment but not on most (all?) host systems because itoa is not a portable standard function.
11
10
12
11
### Changed
12
+ - Simplified the use of ` Array.each ` with a return statement; it's now simply ` Array.find `
13
13
14
14
### Deprecated
15
15
Original file line number Diff line number Diff line change @@ -32,13 +32,7 @@ def self.autolocated_executable
32
32
# if it exists. I'm not sure why we would have both, but if we did
33
33
# a force install then let's make sure we actually use it.
34
34
locations = [ self . force_installed_executable , self . existing_executable ]
35
- locations . each do |loc |
36
- next if loc . nil?
37
- next unless File . exist? loc
38
-
39
- return loc
40
- end
41
- nil
35
+ locations . find { |loc | !loc . nil? && File . exist? ( loc ) }
42
36
end
43
37
44
38
# The autolocated directory of the installation
@@ -49,13 +43,7 @@ def self.autolocated_installation
49
43
# if it exists. I'm not sure why we would have both, but if we did
50
44
# a force install then let's make sure we actually use it.
51
45
locations = [ self . force_install_location , self . existing_installation ]
52
- locations . each do |loc |
53
- next if loc . nil?
54
- next unless File . exist? loc
55
-
56
- return loc
57
- end
58
- nil
46
+ locations . find { |loc | !loc . nil? && File . exist? ( loc ) }
59
47
end
60
48
61
49
# The path to the directory of an existing installation, or nil
Original file line number Diff line number Diff line change @@ -27,21 +27,17 @@ def self.force_install_location
27
27
# @param Array<string> a list of places to look
28
28
# @return [string]
29
29
def self . find_existing_arduino_dir ( paths )
30
- paths . each do |path |
31
- return path if File . exist? path
32
- end
33
- nil
30
+ paths . find ( &File . method ( :exist? ) )
34
31
end
35
32
36
33
# An existing Arduino file in one of the given directories, or nil
37
34
# @param Array<string> a list of places to look for the executable
38
35
# @return [string]
39
36
def self . find_existing_arduino_exe ( paths )
40
- paths . each do |path |
37
+ paths . find do |path |
41
38
exe = File . join ( path , "MacOS" , "Arduino" )
42
- return exe if File . exist? exe
39
+ File . exist? exe
43
40
end
44
- nil
45
41
end
46
42
47
43
# The path to the directory of an existing installation, or nil
Original file line number Diff line number Diff line change @@ -81,10 +81,10 @@ def self.existing_installation
81
81
# @return [string]
82
82
def self . existing_executable
83
83
arduino_reg = 'SOFTWARE\WOW6432Node\Arduino'
84
- Win32 ::Registry ::HKEY_LOCAL_MACHINE . open ( arduino_reg ) do |reg |
84
+ Win32 ::Registry ::HKEY_LOCAL_MACHINE . open ( arduino_reg ) . find do |reg |
85
85
path = reg . read_s ( 'Install_Dir' )
86
86
exe = File . join ( path , "arduino_debug.exe" )
87
- return exe if File . exist? exe
87
+ File . exist? exe
88
88
end
89
89
rescue
90
90
nil
@@ -93,10 +93,7 @@ def self.existing_executable
93
93
# The executable Arduino file in a forced installation, or nil
94
94
# @return [string]
95
95
def self . force_installed_executable
96
- exe = File . join ( self . force_install_location , "arduino_debug.exe" )
97
- return nil if exe . nil?
98
-
99
- exe
96
+ File . join ( self . force_install_location , "arduino_debug.exe" )
100
97
end
101
98
102
99
end
You can’t perform that action at this time.
0 commit comments