Skip to content

Instantly share code, notes, and snippets.

@vidmantas
Last active August 29, 2015 14:10
Show Gist options
  • Save vidmantas/c76f36b21a159b841877 to your computer and use it in GitHub Desktop.
Save vidmantas/c76f36b21a159b841877 to your computer and use it in GitHub Desktop.
#2 užduotis
require 'json'
class Wifi
def initialize(name, &block)
@root_node = name
@json = { @root_node => { } }
instance_eval(&block)
end
def to_s
@json.to_json
end
def method_missing(method_name, *args, &block)
if method_name == :to_ary
super
else
@json[@root_node][method_name] = args.first
end
end
end
def describe(name, &block)
w = Wifi.new(name, &block)
puts w
end
describe "WiFi" do
ssid "ruby"
password "vilnius"
end
# { "WiFi": { "ssid": "wix", "password": "wix1" } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment