Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are quite a few issues with your code -</p> <ol> <li>Use of Un-Ruby style syntax in method names and variable names.</li> <li>Usage of <code>=begin; comment; =end</code> even for single line comments is not nice. Personally I prefer to use # style even for multi-line comments.</li> <li>Interchangeable use of local and instance variables. For example in the last line you search the hash keys for a local variable <code>schemeName</code> and in the subsequent <code>puts</code> you use an instance variable<code>@schemeName</code>, though I suspect you might be trying to achieve interpolation effect for which btw you need to use <code>"#{schemeName}"</code> instead of <code>"@schemeName"</code></li> </ol> <p>However that aside if I understood correctly what you want to achieve (i.e. create a hash of schemes with scheme as key and module as value) then try the following code. In this example I have assumed that you want to have a 1:1 relationship between scheme and module, however if you want to define multiple modules per scheme you can achieve that easily by adding another loop and replacing the string value of scheme with an array in the code below.</p> <pre><code>def add_module schemes = {} scheme_exists = false add_another_scheme = true while add_another_scheme print "Enter Scheme Name: " scheme_name = gets schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false if !scheme_exists print "Enter Module Name: " module_name = gets schemes[scheme_name.chop] = module_name.chop puts "Scheme #{scheme_name.chop} has been added to the system" else scheme_exists = false puts "This scheme has already been added" end print "Enter another scheme? " ask_user_if_would_like_to_add_another_scheme = gets if !(ask_user_if_would_like_to_add_another_scheme.chop == "Y" or ask_user_if_would_like_to_add_another_scheme.chop == "Yes") add_another_scheme = false end end puts schemes end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload