Skip to content

Commit

Permalink
Add / remove frozen string where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Souravgoswami committed Oct 16, 2024
1 parent 11a0498 commit 82ed66e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/linux_stat/net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def total_bytes_received

data = IO.readlines(DEV).drop(2)
index = find_index_of_bytes[0]
data.reject! { |x| x.strip.start_with?('lo:') }
data.reject! { |x| x.strip.start_with?('lo:'.freeze) }
data.map { |x| x.split[index].to_i }.reduce(:+)
end

Expand All @@ -60,7 +60,7 @@ def total_bytes_transmitted

data = IO.readlines(DEV).drop(2)
index = find_index_of_bytes[-1]
data.reject! { |x| x.strip.start_with?('lo:') }
data.reject! { |x| x.strip.start_with?('lo:'.freeze) }
data.map { |x| x.split[index].to_i }.reduce(:+)
end

Expand Down
15 changes: 8 additions & 7 deletions lib/linux_stat/process_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ class << self
#
# If the info isn't available it will return an empty Hash.
def total_io(pid = $$)
return {} unless File.readable?("/proc/#{pid}/io".freeze)
io_file = "/proc/#{pid}/io"
return {} unless File.readable?(io_file)
out = {}

IO.readlines("/proc/#{pid}/io".freeze).each { |x|
IO.readlines(io_file).each { |x|
x.strip!

if x[/^(read|write)_bytes:\s*\d*$/]
Expand Down Expand Up @@ -59,7 +60,7 @@ def total_io(pid = $$)
#
# If the info isn't available it will return an empty frozen String.
def cmdline(pid = $$)
file = "/proc/#{pid}/cmdline".freeze
file = "/proc/#{pid}/cmdline"
return ''.freeze unless File.readable?(file)

_cmdline = IO.read(file)
Expand Down Expand Up @@ -110,7 +111,7 @@ def command_name(pid = $$)
#
# If the info isn't available it will return an empty frozen String.
def process_name(pid = $$)
file = "/proc/#{pid}/stat".freeze
file = "/proc/#{pid}/stat"
return command_name unless File.readable?(file)

name = IO.read(file).split(/(\(.*\))/) &.[](1) &.[](1..-2)
Expand Down Expand Up @@ -424,7 +425,7 @@ def last_executed_cpu(pid = $$)
#
# If the info isn't available it returns an empty Array.
def uid(pid = $$)
file = "/proc/#{pid}/status".freeze
file = "/proc/#{pid}/status"
return nil unless File.readable?(file)

data = IO.foreach(file.freeze).find { |x|
Expand All @@ -448,7 +449,7 @@ def uid(pid = $$)
#
# If the info isn't available or the argument passed doesn't exist as a process ID, it will return an empty Hash.
def gid(pid = $$)
file = "/proc/#{pid}/status".freeze
file = "/proc/#{pid}/status"
return nil unless File.readable?(file)

data = IO.foreach(file.freeze).find { |x|
Expand All @@ -469,7 +470,7 @@ def gid(pid = $$)
# Returns the owner of the process
# But if the status is not available, it will return an empty frozen String.
def owner(pid = $$)
file = "/proc/#{pid}/status".freeze
file = "/proc/#{pid}/status"
return ''.freeze unless File.readable?(file)

gid = IO.foreach(file.freeze).find { |x|
Expand Down
2 changes: 1 addition & 1 deletion lib/linux_stat/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module LinuxStat
VERSION = "2.6.0"
VERSION = "2.6.0".freeze
end

0 comments on commit 82ed66e

Please sign in to comment.