i'm trying set bounds array later printed in console , summed. lower bound ($a) should less 50 , wrote code evaluate that, want re-prompt number if higher number typed. far, google , experimentation have failed me. def num_a print "pick number 1 50: " $a = integer(gets.chomp) until $a < 50 puts "um, try again please." # need here prompt response # until $a less 50 end end you restructure loop prompt , call gets both inside it: def num_a # start number doesn't meet condition = 50 # check if number meets condition yet until < 50 # ask user enter number print "pick number 1 50: " = integer(gets.chomp) # ask try again if number isn't under 50 puts "um, try again please." unless < 50 end # return entered value caller end also, i've shown in example, recommend avoiding use of global variables ( $a in case).
i trying parameter validation outside of rails. def create_statement(action, ...) valid_one_of(action, ['add', 'move', 'delete']) ... end validation method: def valid_one_of(input, valid_values) return true if valid_values.include?(input) raise "#{input} not valid value #{input.var_name}" end sample call: create_statement('bob') so output be: bob not valid value action the problem how input.var_name ? i workaround pass valid_one_of(action, ['add', 'move', 'delete'], 'action') (and use 3rd parm output) doesn't seem feels bit redundant. if not possible access variable name there more dry coding style workaround? i don't know of way name of local variable, , if could, name want? name of parameter define on method definition? name of variable in caller? i don't think "work-around" horrible, suggest couple of slight variations might read littl...
i using twitterizer dll post twit on twitter via oauth method give me error. "whoa there! there no request token page. that's special key need applications asking use twitter account. please go site or application sent here , try again; mistake." and code is: using system; using twitterizer; public partial class home : system.web.ui.page { protected void page_load(object sender, eventargs e) { var oauth_consumer_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; var oauth_consumer_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; if (request["oauth_token"] == null) { oauthtokenresponse reqtoken = oauthutility.getrequesttoken(oauth_consumer_key, oauth_consumer_secret, request.url.absoluteuri); response.redirect(string.format("http://twitter.com/oauth/authorize?oauth_token+{0}", reqtoken.token)); } else { string requesttoken = request["oauth_token"]....
Comments
Post a Comment