-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Input subclass constructors force use of positional arguments #14
Comments
My goal is to be able to use a pattern like this: def get_profile
name = HtmlUI::Textbox.new(
key: :name,
label: "Name"
)
age = HtmlUI::Textbox.new(
key: :age,
label: "Age (to the nearest year)",
default: Integer,
width: 4
)
height = HtmlUI::Textbox.new(
key: :height,
label: "Height",
default: Length,
width: 10
)
drink = HtmlUI::Dropdown.new(
key: :poison,
label: "Choose your poison:",
default: "Brandy",
options: ["Bourbon","Brandy","Whiskey","Wine"]
)
hobby = HtmlUI::Listbox.new(
key: :hobby,
label: "Choose your favorite pasttime:",
default: "Golf",
options: ["Golf","Tennis","Squash","Fishing"],
rows: 4
)
window = HtmlUI::InputBox.new(
title: "Personality Profile",
inputs: [ name, age, height, drink, hobby ]
)
data = window.prompt(Hash)
# data validation ...
end One advantage is that any mistakes in calling input control constructors will raise exceptions that are not nested within the |
Yes, when looking at the examples as I was replying to one of the other threads I was bothered how unclear it was to read which argument was the default one. Named arguments is preferable, particularly when you have more than a couple of arguments like in these cases. |
I have no problem with allowing a small set of positional args to default to their matching named args.
You already correctly have the 3 "base" arguments ( Do not think myself that we need a total overhaul.
To make things easier at the console I do this: UX = Example::HtmlInputBox::HtmlUI ... then I can enter tests like so: dlg = UX::InputBox.new(
title: "Enter Data...",
inputs: [ UX::Textbox.new("Name"), UX::Textbox.new("Age",Integer), UX::Textbox.new("Height",Length) ]
)
I think as said in the other thread, it's no problem adding a The only other alternative is a loose coupling by having the I am not really keen on this as many places in the code the I also like the idea that an input object "knows" what it's I like the way I am now leaning to let the developer decide on a input by input basis what the key will be ... either the default to the |
HtmlUI::Input
subclass constructors force use of positional arguments.This is becoming a problem in adding more features.
One is adding a
key: "keyname"
argument for hash output.The text was updated successfully, but these errors were encountered: