Skip to content

Validates which arguments are required and which are optional. 👮 ⛔

License

Notifications You must be signed in to change notification settings

BitConceptIO/argument_labeled

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

argument_labeled

Add a handful of convenient methods to Module, which make working with argument hashes in Ruby a bit easier.

Usage

require 'argument_labeled'

class ReadFile
  required_arguments :dir, :filename
  def initialize(opts = {})
    @dir = opts[:dir]
    @filename = opts[:filename]
    Dir.chdir(@dir) unless @dir.nil?
  end
  default_arguments {{mode: 'r'}}
  def open_file(opts = {})
    file = File.open(@filename, opts[:mode] ).readlines
    puts file.join(" ")
  end
  allowed_arguments :text
  def write_in_file(opts = {})
    file = File.open(@filename) do |file|
      file.write(opts[:text])
      file.close
    end
  end
end
file = ReadFile.new(DIR, FILENAME)
file.open_file(mode: 'r+')
file.write_in_file(text: 'Hello World')

About

Validates which arguments are required and which are optional. 👮 ⛔

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%