In Ruby 2.1.1 I defined the following method:
def post(url, params={}, send_json: false, success_only: true)
This is called within the same object in another method privateToken
like so:
self.post("#{@url}/api/v3/session", {
:login => @user,
:password => @pass,
})['private_token']
However, calling privateToken
in initialize
for this object results in:
<script>:207:in `privateToken': unknown keywords: login, password (ArgumentError)
from <script>:199:in `initialize'
from <script>:575:in `new'
from <script>:575:in `<main>'
If I change the post
method to accept params
as a keyword argument then this error is avoided:
def post(url, params: {}, send_json: false, success_only: true)
# ..then in method 'privateToken':
self.post("#{@url}/api/v3/session", params: {
:login => @user,
:password => @pass,
})['private_token']
Could someone please explain why this happens? I haven't seen any mention of hash expansion to keywords in the Keyword arguments documentation. And from what I've read the argument ordering should be: standard arguments, default arguments, keyword arguments.