Should methods be inside classes? in Ruby I have coded more in Python but I am learning Ruby now. So I am trying to write a solution to create a family_tree and add and get relationships. The code below is of the file that contains the main function which is called from the command line. The below code works and solves the problem but I have written methods without classes. In python it is acceptable. Is is acceptable in ruby? Even though the code works is this how it is written in Ruby? Or does this need refactoring? If yes then please tell how?
#main_file.rb
require_relative 'family'
require_relative 'family_tree'
include FamilyTree
require_relative 'constants'
require_relative 'errors'


def is_valid_input(command)
  #User input Validation
  commands = command.split(' ')
  return false unless (commands &amp;&amp; INPUT_FUNCTION_MAPPER.key?(commands[0]))
  return false if (commands[0] == &quot;ADD_CHILD&quot; &amp;&amp; commands.length != 4)
  return true
end

def create_family_tree(family_tree)
  #Initializing the family
  family_name = family_tree[:name]
  members = family_tree[:members]

  family = Family.new(family_name)
  members.each do |name, gender, mother_name|
    family.add_member(name, gender, mother_name)
  end
  family
end

def execute_command(command, family)
  result = nil
  unless is_valid_input(command)
    raise InvalidParametersError, &quot;Command is not valid&quot;
  end
  command = command.split(&quot; &quot;)
  if command[0] == &quot;ADD_CHILD&quot;
    mother, name, gender = command[1..]
    result = family.add_member(name, gender, mother)
  end
  result
end

def main_method
  if ARGV.length != 1
    raise InvalidParametersError, &quot;Please provide an input file&quot;
  end
  input_file = ARGV[0]
  unless File.file?(input_file)
    raise InvalidParametersError, &quot;Input file does not exist&quot;
  end

  family = create_family_tree(FAMILYTREE)
  File.readlines(input_file).each do |line|
    line = line.strip
    puts execute_command(line, family)
  end
end

main_method()


This is executed as below:
ruby main_file.rb input.txt
This &quot;global function&quot; style works for small scripts but isn't reusable.
A more practical problem with it is if you want to have state that is shared between functions, you don't have anywhere to store it (well, you could use global variables ($var), but that's prone to conflicts).
For a more encapsulated design, create a class that does the work and move the methods into the class. See for example definition and usage.