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
3
votes
3 answers

Ruby Koans about message passing "send" block & arguments

I am working on Ruby Koans about_message_passing.rb and got the code working for method_missing as follows: def method_missing(method_name, *args, &block) @messages << method_name @object.__send__(method_name, *args, &block) end This code seems…
ZenBalance
  • 10,087
  • 14
  • 44
  • 44
2
votes
2 answers

Can you combine keyword argument expansion with regular keyword arguments?

What I want to do is this: logged_in = { 'logged_in': True, 'username' : 'myself', } print render_template('/path/to/template.html', **logged_in, title = 'My page title', more = 'even more stuff', ) But that doesn't…
st-boost
  • 1,877
  • 1
  • 14
  • 17
2
votes
2 answers

In Julia how to deal neatly with Zero Dimensions and Iterators

Consider the following scenario: do_something( v :: Vector{ T } ) where { T <: Integer } = println( "v = $v" ) function d_dep( d :: Integer ) axis_iters = fill( -1:1, d ) for ig in Iterators.product( axis_iters ... ) g = [ ig ...…
Ian Bush
  • 6,996
  • 1
  • 21
  • 27
2
votes
2 answers

Ruby hash.dig using array as argument?

I have a nested hash of data foo => { 'user' => { 'address' => { 'street' => '1234' } } } I can access the values using Hash.dig foo.dig('user', 'address', 'street') 1234 How would you use hash.dig when the values are variable,…
spuder
  • 17,437
  • 19
  • 87
  • 153
2
votes
1 answer

How is the splat operator understood when applied to a range expression?

I found that the expression [*1..4] returns the same as if I would do a (1..4).to_a, but I don't understand the syntax here. My understanding is that * is - being a unary operator in this case - to be the splat operator, and to the right of it, we…
user1934428
  • 19,864
  • 7
  • 42
  • 87
2
votes
2 answers

How to access a Ruby splat argument?

I have overridden the send_devise_notification methods from my devise gem. I need to access the first element in the *args array, and I would assume this can be achieved with *args[0]. I am expecting a string, but check out the strange output…
JohnSmith1976
  • 536
  • 2
  • 12
  • 35
2
votes
1 answer

Scala Splat inner workings

I know in scala I can say def foo(x: Int*) ... foo(Seq(1,2,3): _*) But I can't say foo(Seq(1,2,3)) So there must be some implicit conversion going on. What is this implicit conversion? What is the actual method that makes this happen. Or, if I'm…
munk
  • 12,340
  • 8
  • 51
  • 71
2
votes
2 answers

Is there a way to use non Tuple objects with splat operator in Crystal?

Is there some function or syntax construction to make next examples work? Invoke Hash#values_at function with an Array argument: h = {"a" => 1, "b" => 2, "c" => 3} ary = ["a", "b"] h.values_at(*ary) # Error: argument to splat must be a tuple, not…
2
votes
1 answer

Can't register a View and ViewModel between 2 assemblies (UWP, Splat)

Using the latest RxUI v8 preview and Splat 2.0, in a UWP project referencing a .Net Standard 2.0 library, I can't register my view and viewmodel unless they reside in the same assembly. I have: Locator.CurrentMutable.RegisterLazySingleton(() => new…
Maximus
  • 1,441
  • 14
  • 38
2
votes
1 answer

Expanding empty hash in variable with double splat in Ruby

I got this strange behavior trying to expand the hash variable using double splat. Do not know why this is happening. My ruby version ruby 2.2.6p396 (2016-11-15 revision 56800) Scenario class MyClass def my_method;…
rafaels88
  • 839
  • 1
  • 6
  • 19
2
votes
1 answer

Is there a way without a (*)splat argument to pass multiple arguments in Ruby?

I need to write a method that takes an unknown number of arguments (hence the *splat) but that passes a yields_with_args spec. The code: def eval_block(*args, &block) raise "NO BLOCK GIVEN!" if block.nil? block.call(args) end The…
Andrea McKenzie
  • 239
  • 1
  • 12
2
votes
2 answers

Is it possible to invert a splat in Ruby?

Ruby's splat operator * may be used to coalesce def one_argument(*a) ... end one_argument(1, 2, 3) or split def multiple_arguments(a, b, c) ... end multiple_arguments(*[1, 2, 3]) multiple values, depending on the context. Is it possible to…
Max Wallace
  • 3,609
  • 31
  • 42
2
votes
2 answers

ReactiveUI.Routing dependency on Splat

The ReactiveUI.Routing requires us to register the views in Splat container (Locator.CurrentMutable). If I don’t register it with Splat it is not working. If we are using some other IOC container or service locator like Ninject, is tere a way to…
Rajan
  • 121
  • 7
2
votes
1 answer

Local or remote execution of powershell script with generic parameters

In a development team, I would like to have the same test scripts to be executed locally by a developper or remotely by our test platform. Here is what I would like to use as premises for each script # Test local/remote execution by reading C:\…
FoxAlfaBravo
  • 106
  • 1
  • 12
2
votes
2 answers

Splat operator or regex not working?

I'm new to Ruby and building Chess as a learning exercise. I'm attempting to refactor some code, and I'm stymied. Why does this work: @available_moves = [] #part of castling logic @available_moves << "c1" if empty?("b1") && empty?("c1") &&…
spectre6000
  • 455
  • 4
  • 17