Skip to content

Instantly share code, notes, and snippets.

@3limin4t0r
Created April 23, 2021 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3limin4t0r/9030c9102f8ae4b0744bffb7819fbd38 to your computer and use it in GitHub Desktop.
Save 3limin4t0r/9030c9102f8ae4b0744bffb7819fbd38 to your computer and use it in GitHub Desktop.
class Hostel
attr_accessor :anv, :bnv
ITEM_NAMES = %w[av bv] # or ['av', 'bv']
def initialize
@items = ITEM_NAMES.to_h { |name| [name, []] }
end
ITEM_NAMES.each do |name|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
def #{name}
@items[#{name.inspect}]
end
def #{name}=(value)
@items[#{name.inspect}] = value
end
RUBY
end
def allot_houses(num, cs, fp)
key = "#{cs}#{fp}"
if @items.key?(key)
@items[key].push(num)
else
puts 'Nope'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment