Re-Opened Nested Module Anomaly in Ruby

Re-opened nested module anomaly in Ruby

The module keyword sets a namespace context that is checked for references to existing names of Modules. These namespaces are then searched inner-to-outer to resolve references to Module (and Class) names.

In your first example, it looks like you may need to define E.e inside module E block, but in fact you don't:

module A
module E
end
end
module A
def E.e
end
end

What happens in both your examples is that Ruby looks at the current namespace, and tries <namespace>::E as a module name. So in both examples, the first thing it checks is in fact A::E::E which does not exist. Then it falls back to the next context. Which is where the examples differ: In the first example it is A::E which is valid, in the second example, it is just E which is not. The error that it then throws relates to the first name it checked.

Return exitcode of a HIDE instance of CMD opened by win32ole module?

thanks you 2

i resolved this problem trying another more efficient method:

require 'win32/api'
include Win32

# Callback example - Enumerate windows
EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
buf = "\0" * 200
GetWindowText.call(handle, buf, 200);

if (!buf.index(param).nil?)
puts "window was found: handle #{handle}"
0 # stop looking after we find it
else
1
end
}

EnumWindows.call(EnumWindowsProc, 'title here')

bye

Re-opened nested module anomaly in Ruby

The module keyword sets a namespace context that is checked for references to existing names of Modules. These namespaces are then searched inner-to-outer to resolve references to Module (and Class) names.

In your first example, it looks like you may need to define E.e inside module E block, but in fact you don't:

module A
module E
end
end
module A
def E.e
end
end

What happens in both your examples is that Ruby looks at the current namespace, and tries <namespace>::E as a module name. So in both examples, the first thing it checks is in fact A::E::E which does not exist. Then it falls back to the next context. Which is where the examples differ: In the first example it is A::E which is valid, in the second example, it is just E which is not. The error that it then throws relates to the first name it checked.

Return exitcode of a HIDE instance of CMD opened by win32ole module?

thanks you 2

i resolved this problem trying another more efficient method:

require 'win32/api'
include Win32

# Callback example - Enumerate windows
EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
buf = "\0" * 200
GetWindowText.call(handle, buf, 200);

if (!buf.index(param).nil?)
puts "window was found: handle #{handle}"
0 # stop looking after we find it
else
1
end
}

EnumWindows.call(EnumWindowsProc, 'title here')

bye

Chef - run install block based on variable condition

The problem is Chef's two-pass model. See https://coderanger.net/two-pass/ for the full explanation for for this you just need to move the condition check in to the only_if block itself since that is delayed until converge time: only_if { ::File.directory?('/opt/MyPkg/conf') }.

Using the fatal log level is also probably not a good idea as this isn't actually a fatal error as written.

Validation failed: Email can't be blank, Password can't be blank - Not Blank

Like the dump of the parameters show, the hash for the values you're after are nested within "add_clients":

"add_clients"=>{
"name"=>"test 3",
"email"=>"testform3@gmail.com",
...
}

So to get the value of, say, email, the code would be params[:add_clients][:email] etc.

However I would also checkout the documentation on Strong Parameters as well as how to organise RESTful routing/controllers in Rails as you're breaking a number of established patterns with your code.



Related Topics



Leave a reply



Submit