proc

Why do Ruby procs/blocks with splat arguments behave differently than methods and lambdas?

别来无恙 提交于 2019-12-18 16:46:22
问题 Why do Ruby (2.0) procs/blocks with splat arguments behave differently than methods and lambdas? def foo (ids, *args) p ids end foo([1,2,3]) # => [1, 2, 3] bar = lambda do |ids, *args| p ids end bar.call([1,2,3]) # => [1, 2, 3] baz = proc do |ids, *args| p ids end baz.call([1,2,3]) # => 1 def qux (ids, *args) yield ids, *args end qux([1,2,3]) { |ids, *args| p ids } # => 1 Here's a confirmation of this behavior, but without explanation: http://makandracards.com/makandra/20641-careful-when

Chaining & to_proc on symbol

懵懂的女人 提交于 2019-12-18 04:19:06
问题 It's well known to Rubyist & will call to_proc on a symbol, so [:a, :b, :c].map(&:to_s) is equivalent to [:a, :b, :c].map { |e| e.to_s } # => ["a", "b", "c"] Say I want to call another method right after to_s , these two implementations will work: [:a, :b, :c].map { |e| e.to_s.upcase } [:a, :b, :c].map(&:to_s).map(&:upcase) My question is, is there a way to chain the & Symbol#to_proc call in one parameter? Something like: [:a, :b, :c].map(&:to_s:upcase) Thanks! 回答1: If you're only doing: %i[a

Parsing /proc/maps? [closed]

流过昼夜 提交于 2019-12-14 03:38:10
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . I wrote the following code in C. What I have done so far is open the proc directory and read the processes inside - dictories that did not consist of numerical characters were simply disregarded as I only want to look at the numeric directories. What I want to do is to print the PID of all the

How to transfer kernel data to user data using procfs

 ̄綄美尐妖づ 提交于 2019-12-13 21:44:00
问题 I am calculating a timestamp in kernel and storing it in a buffer as shown in the code below. I want to make this data available to the user space program by using process file system (procfs). I am finding it very difficult to understand the procfs file system. Can someone help me understand how to do this, or point me in the right direction of some document or tutorial regarding this? //this code is at network device driver level. int netif_rx(struct sk_buff *skb) { __net_timestamp(skb);//I

SAS: Mean, median, max and percentiles by two variables

荒凉一梦 提交于 2019-12-13 09:45:24
问题 I have a dataset structured with 5 columns. Month, User, Num1, Num2, Num3. I'm trying to calculate, for each Num1 Num2 and Num3, the mean, median, max, 25th and 75th percentile for each permutation of Month and User. I have tried proc univariate but I can't do it without creating a macro and manual steps for each Month and User permutation. My ideal output would then look like this, and separate outputs for Num1 Num2 Num3: http://i.imgur.com/YC67LV1.png Thanks! 回答1: PROC Means does what you

SAS: PROC TABULATE Rearrange Header Subgroups

主宰稳场 提交于 2019-12-13 07:04:47
问题 Question: How do I control the order of subgroups in the output of PROC TABULATE? For instance, suppose I have this output, namely (A, B) within segment : data example; input group $ segment $; datalines; 1 A 1 B 2 A 2 A 3 B 3 B ; run; proc tabulate data = example; class group segment; table group all, all = 'Total'*n segment*n; run; +-----------------------+------------+-------------------------+ + + + segment + + + +------------+------------+ + + Total + A + B + + +------------+------------

In Ruby, can you use the lambda or or Proc call method to invoke an iterator? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:29:12
问题 This question already has answers here : Trouble yielding inside a block/lambda (4 answers) Closed 2 years ago . I would like to create an iterator that I can pass to a method for the method to call. #!/usr/bin/env ruby puts "------------------------------------" puts "1 This works." puts "------------------------------------" 1.times {|who| puts "Position #{who} works!"} puts "------------------------------------" puts "2 This works." puts "------------------------------------" aBlock = Proc

GDB can't insert internal breakpoint

♀尐吖头ヾ 提交于 2019-12-12 19:12:20
问题 I added two breakpoints in functions of one shared library (.so) and ran gdb 7.4 and attached it to a process. Gdb hit the breakpoint and I ran n for several steps, and gdb reported the following errors(with bold text): (gdb) b [function name] Breakpoint 1 at 0xf1f28a49: file ../../../../../[file name].cpp, line 167. Breakpoint 2 at 0xf1f2dae5: file ../../../../../[file name].cpp, line 60. warning: Multiple breakpoints were set. Use the "delete" command to delete unwanted breakpoints. (gdb) c

Why doesn't to_proc work inside Ruby refinements?

早过忘川 提交于 2019-12-12 10:52:22
问题 It seems that to_proc doesn't work on methods defined in refinements: module ArrayExtensions refine Array do def sum reduce(0, :+) end end end using ArrayExtensions puts [[1, 2, 3]].map { |array| array.sum } # => 6 puts [[1, 2, 3]].map(&:sum) # => array.rb:13:in `map': undefined method `sum' for [1, 2, 3]:Array (NoMethodError) puts [1, 2, 3].method(:sum).to_proc.call # => array.rb:14:in `method': undefined method `sum' for class `Array' (NameError) Is this the intended behavior? Is there a

How does the “#map(&proc)” idiom work when introspecting module classes?

丶灬走出姿态 提交于 2019-12-12 07:45:19
问题 Presenting the Idiom I found an interesting but unexplained alternative to an accepted answer. The code clearly works in the REPL. For example: module Foo class Bar def baz end end end Foo.constants.map(&Foo.method(:const_get)).grep(Class) => [Foo::Bar] However, I don't fully understand the idiom in use here. In particular, I don't understand the use of &Foo , which seems to be some sort of closure, or how this specific invocation of #grep operates on the result. Parsing the Idiom So far, I