Last active
August 29, 2015 14:10
-
-
Save vidmantas/c76f36b21a159b841877 to your computer and use it in GitHub Desktop.
#2 užduotis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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