Search Results

Search found 2 results on 1 pages for 'user204078'.

Page 1/1 | 1 

  • Scope of Constants in Ruby Modules

    - by user204078
    I'm having a little problem with constant scope in mixin modules. Let's say I have something like this module Auth USER_KEY = "user" unless defined? USER_KEY def authorize user_id = session[USER_KEY] def end The USER_KEY constant should default to "user" unless it's already defined. Now I might mix this into a couple of places, but in one of those places the USER_KEY needs to be different, so we might have something like this class ApplicationController < ActionController::Base USER_KEY = "my_user" include Auth def test_auth authorize end end I would expect that USER_KEY would be "my_user" when used in authorize, since it's already defined, but it's still "user", taken from the modules definition of USER_KEY. Anyone have any idea how to get authorize to use the classes version of USER_KEY?

    Read the article

  • Ruby: What's going on here?

    - by user204078
    This question is based off some really odd code I recently found in a colleagues work. He claims not to know how it works only he copied it from somewhere else. That's not good enough for me I want to understand what's going on here. Say we have something like (test1, test2, test3="3", test4="4") the result will be that test1 == "3", test2 == "4", test3 == nil and test4 == "4" I understand why this happens, but if we do something like (test1, test2, test3="3", test4="4", test5 = "5", test6 = "6") now the result is test1 == "3", test2 == "4", test3 == "5", test4 == "6", test5 == "5", test6 == "6" Why isn't test5 == nil?

    Read the article

1