Questions tagged [splat]

The `*` operator as used in Ruby. So called because it looks like an insect that's splatted on a windscreen.

The * operator as used in Ruby. So called because it looks like an insect that's splatted on a windscreen.

166 questions
2
votes
3 answers

concatenate with splat ruby

say I have arr = [1,2,3] How can I change this method so it adds each argument to the array? def add(*number) arr << *number end So add(4,5,6) produces: arr #=> [1,2,3,4,5,6]
stevenspiel
  • 5,775
  • 13
  • 60
  • 89
2
votes
4 answers

Ruby syntax error, unexpected '=', expecting ')'

I am attempting to write my own solution to a Ruby exercise from Rubymonk where the purpose is to create three methods (add, subtract, and calculate) so when 'calculate' is called you can determine whether or not numbers are added or subtracted…
John
  • 443
  • 8
  • 19
2
votes
1 answer

How to pass an array as an argument list

Ruby's documentation displays method signatures as: start_with?([prefixes]+) → true or false which looks like an array to me, but it is not. You can pass a single string or various string as arguments, like so: "hello".start_with?("heaven", "hell")…
andy
  • 8,775
  • 13
  • 77
  • 122
1
vote
1 answer

Ruby's Unary * Operator

Possible Duplicate: What is the * operator doing to this string in Ruby I ran across the following code when looking for an easy way to convert an array to a hash (similar to .Net's ToDictionary method on IEnumerable... I wanted to be able to…
Eric Andres
  • 3,417
  • 2
  • 24
  • 40
1
vote
2 answers

Is there a name for the function that returns a positionally-expanding version of its argument?

Consider splatter in this Python code: def splatter(fn): return lambda (args): fn(*args) def add(a, b): return a + b list1 = [1, 2, 3] list2 = [4, 5, 6] print map(splatter(add), zip(list1, list2)) Mapping an n-ary function over n zipped…
Ian Henry
  • 22,255
  • 4
  • 50
  • 61
1
vote
1 answer

What are starred variables in Ruby?

What are starred variables like *arr? *arr = "sayuj" => ["sayuj"] *arr = *%w{i am happy} => ["i", "am", "happy"] *arr = %w{i am happy} => [["i", "am", "happy"]]
Sayuj
  • 7,464
  • 13
  • 59
  • 76
1
vote
1 answer

Sending Params Correctly without Interpolation with Splat

Can I directly import these parameters to my function with their correct types with only value with respectively? $appparams = @{ sname = "RandomAppName" # type: string sdata = [byte]12 # type: Byte sgroup = $null …
Ichigo Kurosaki
  • 135
  • 1
  • 6
1
vote
2 answers

Using Splat in Invoke-Command AND passing arguments relevant to the machine

I'm using Invoke-Command, but this question can be relevant to any command using splat. I essentially want to pass two sets of variables that will be useful in the splat command, but I'm not sure how I can do this. In the code below, the…
1
vote
2 answers

Idiomatic way to receive an object or array of objects, transform them, and add to existing array

I have a method that can receive either a single object, or an array of those objects. (The YAML file I'm pulling from sometimes has foo: bar and sometimes a list of foo: [bar1, bar2].) Each time this method is called, it should transform the value…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
1
vote
0 answers

Strange evaluation order using Python's splat (*) in MacBookM1

I noticed a strange behavior while using the splat operator. I ran the following code on different computers: def func(m): m(1) return [] messages = [] print( [*messages, *func(messages.append)] ) Test 1 PC: MacBook Air M1 Python…
David Sand
  • 11
  • 2
1
vote
1 answer

How to pass array as individual arguments in ruby?

I am trying to think of a more elegant way to pass elements of an array as individual arguments to a method. So far, I have the following code: def fetch_data(keywords) Product.where("name ILIKE ? AND type ILIKE ?",…
ninja_nugget
  • 712
  • 1
  • 8
  • 19
1
vote
1 answer

I need to use a splat operator within a PHP docblock and cannot figure out how to escape the character

I am using codeception and running multiple sets of example data. I am sending in multiple accept headers, one of which is "*/*". so the example code is: /** * My description of the test * * GET a/path/i/am/testing * *…
so_blue
  • 41
  • 1
  • 4
1
vote
2 answers

How to convert a 1D array to tuple in Julia?

I want to reshape an array in Julia using the reshape function but the shape of the new array is stored as a 1-D array itself. reshape takes tuples as argument but not 1D array. For example, I want to be able to do this: reshape([1 2 3 ; 4 5…
1
vote
1 answer

Pass PHP splat parameters to another function

If I have one PHP function which accepts splat parameters: function1(...$parms1) {...} and I call this function from another function which also accepts splat parameters: function2(...$parms2) {function1($parms2);} the invocation of function1…
PHPNoob
  • 57
  • 5
1
vote
0 answers

How do I find the code that's failing an assertion error in NodeConstant.cpp when it's being parsed by culam?

WARNING: This question pertains to the Ulam compiler. This tag doesn't exist yet on SO, so it isn't tagged properly. It's tagged with "splat" instead, which is a programming language related to Ulam. This is not the typical use case for this tag on…