- Nov 2020
-
guides.rubyonrails.org guides.rubyonrails.org
-
You can use the match method with the :via option to match multiple verbs at once:
-
-
github.com github.com
-
Dart Sass has replaced Ruby Sass as the canonical implementation of the Sass language.
-
- Oct 2020
-
github.com github.com
-
Probably wouldn't work for capybara-based tests where it forks a different process for the web server?
-
-
engineering.appfolio.com engineering.appfolio.com
-
-
optcarrot, is a headless NES emulator that the Ruby core team are using as a CPU-intensive optimization target.
-
-
github.com github.com
-
StackProf.start(mode: :cpu) StackProf.stop StackProf.results('/tmp/some.file')
-
-
-
stackoverflow.com stackoverflow.com
-
However, if perform was creating threads and you ended up with closures inside perform, then you could end up with several threads referencing the same local variables captured through the closures. So you do have to be careful about scope issues when you create threads but you don't have to worry about it when dealing with simple methods that only work with local variables
Однако, если выполнение создавало потоки, и вы закончили с замыканиями внутри выполнения, тогда вы могли бы получить несколько потоков, ссылающихся на одни и те же локальные переменные, захваченные с помощью замыканий. Таким образом, вы должны быть осторожны с проблемами области при создании потоков, но вам не нужно беспокоиться об этом при работе с простыми методами, которые работают только с локальными переменными.
-
The local variables, such as your hash, are local to the particular invocation of the surrounding method. If two threads end up calling perform at the same time, then each call will get its own execution context and those won't overlap unless there are shared resources involved: instance variables (@hash), class variables (@@hash), globals ($hash), ... can cause concurrency problems. There's nothing to worry about thread-wise with something simple like your perform.
Локальные переменные, такие как ваш хэш, являются локальными для конкретного вызова окружающего метода. Если два потока вызывают выполнение одновременно, то каждый вызов получит свой собственный контекст выполнения, и они не будут перекрываться, если не задействованы общие ресурсы: переменные экземпляра (@hash), переменные класса (@@ hash), глобальные переменные. ($ hash), ... может вызвать проблемы параллелизма. Не нужно беспокоиться о потоковой передаче с чем-то простым, например, с вашей работой.
-
- Sep 2020
- Aug 2020
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
It's unfortunate, but I can understand why they decided this way.
-
-
www.onthegosystems.com www.onthegosystems.com
-
Ruby is the programming language used in Translation Proxy. For Sarah, Object Oriented Design “done the Ruby way” is so enjoyable and is the part of her work that she likes most.
-
- Jul 2020
-
-
Ruby has some really nice libraries for working with linked data. These libraries allow you to work with the data in both a graph and resource-oriented fashion, allowing a developer to use the techniques that best suit his or her use cases and skills.
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
api.rubyonrails.org api.rubyonrails.org
-
Time.current returns said timestamp, and Time.now its equivalent in the system time zone.
-
-
ruby-doc.org ruby-doc.org
-
Since Ruby 1.9.2, Time implementation uses a signed 63 bit integer, Bignum or Rational. The integer is a number of nanoseconds since the Epoch which can represent 1823-11-12 to 2116-02-20. When Bignum or Rational is used (before 1823, after 2116, under nanosecond), Time works slower as when integer is used.
Tags
Annotators
URL
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
There is a usability problem here, it's basically impossible to read the output of Time#inspect in such a case, even though the input was readable.
-
So, which is better? t.inspect # => "2007-11-01 15:25:00 8483885939586761/68719476736000000 UTC" t.inspect # => "2007-11-01 15:25:00.123456789000000004307366907596588134765625 UTC"
-
-
github.com github.com
-
sourcediving.com sourcediving.com
-
Introducing Module#const_source_locationUsing Method#source_location made finding the location of any method fairly easy. Unfortunately, there wasn’t an equivalent for constants. This meant that unless the constant you needed to find was defined in your codebase, finding its source location was not easy.
-
-
blog.toshima.ru blog.toshima.ru
-
To stop emitting the warnings, just add RUBYOPT=-W:no-deprecated.
-
-
www.ruby-lang.org www.ruby-lang.org
-
Enumerable#tally is added. It counts the occurrence of each element. ["a", "b", "c", "b"].tally #=> {"a"=>1, "b"=>2, "c"=>1}
-
Enumerator::Lazy#eager is added. It generates a non-lazy enumerator from a lazy enumerator.
-
A beginless range is experimentally introduced. It might not be as useful as an endless range, but would be good for DSL purposes.
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
It does change it, but it makes it much simpler in my opinion. It is basically "the receiver is statically the explicit literal special variable self or implicit." This gets rid of the current exception for private writer methods (self.foo = bar).
Tags
Annotators
URL
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
I guess much like Range literals in general, it's often needed to have parens around them.
Tags
Annotators
URL
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
Why don't you allow a range without end, like (1..)? There are two advantages. First, we can write ary[1..] instead of ary[1..-1]. The -1 is one of the most I dislike in Ruby. It is very magical, ugly, redundant, and disappointing. I envy Python's ary[1:]. I know that ary.drop(1) is slightly fast, but too long for such a common operation, IMO. Second, we can write (1..).each {|n| ... }.
-
-
github.com github.com
-
stackoverflow.com stackoverflow.com
-
require 'set' class Array def uniq_elements(&prc) prc ||= ->(e) { e } uniques, dups = {}, Set.new each do |e| k = prc[e] ((uniques.key?(k)) ? (dups << k; uniques.delete(k)) : uniques[k] = e) unless dups.include?(k) end uniques.values end end
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
An even more straightforward way is to use group_by
-
-
ruby-doc.org ruby-doc.org
-
Set implements a collection of unordered values with no duplicates.
-
-
twitter.com twitter.com
-
To me the difference between [1,1,2,2,3,3] and [1,2,3] is not []
-
It’s even worse that there’s no alternative method that does the unsurprising thing IMO.
-
Are you angry now? Because I’m angry.
-
You should see me doing a write up for a Ruby feature suggestion only to discover that Array#- is hijacked for non-mathematical reasons
-
Oh. Oh no. That's... not a thing that should be. People wonder why we can't get be more popular with science / math academics.
-
I don't think this is a good overload of 'subtraction'1Olivier Lacan@olivierlacan·Jan 14, 2019Yup. I don’t either.
-
but not as two methods called Array#- and Array#difference. As something like Array#set_difference maybe, or even Array#subtract_all, maybe.
-
-
github.com github.com
-
One may expect Array#- to behave like mathematical subtraction or difference when it doesn't. One could be forgiven to expect the following behavior: [1,1,2,2,3,3,4,4] - [1,2,3,4] => [1,2,3,4]
-
I'll freely admit I was surprised by this behavior myself since I needed to obtain an Array with only one instance of each item in the argument array removed.
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
If you answer is yes, then we are doing this wrong because subset? or part_of method should be in a parent class (maybe Enumerable class ) in order for it to work for subset, array, hash and any data structure that inherit from it Enumerable.
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
Arrays are not sets. Trying to treat them as if they are is an error, and will create subtle problems. What should be the result of the following operations? [1, 1] | [1] [1] | [1, 1] Of course, there are more interesting examples. These two are to get you started. I don't care what the results currently are. I don't care what you think they should be. I can present extremely strong arguments for various answers. For this reason, I believe that #| is an ill-defined concept. Generalizing an ill-defined concept is a world of pain. If you insist on treating objects of one class as if they were members of a different class, there should be bumps in the road to at least warn you that maybe this is a bad idea. I'm not going to argue that we should remove or deprecate #|. I don't think of myself as a fanatic. But encouraging this sort of abuse of the type system just creates problems.
-
I do not understand why concat modify the array, as most of the method of the Array class has a ! method for that. Should I also introduced a concat! method?
-
-
github.com github.com
Tags
Annotators
URL
-
-
github.com github.com
-
Tags
Annotators
URL
-
- Jun 2020
-
stackoverflow.com stackoverflow.com
-
What would be nice is if JavaScript had a built-in way to do what I can do in Ruby with:
> I18n.interpolate('Hi, %{name}', name: 'Fred') => "Hi, Fred"
But to be fair, I18n comes from i18n library, so JS could just as easily (and I'm sure does) have a library that does the same thing.
Update: Actually, you can do this in plain Ruby (so why do we even need
I18n.interpolate
?):main > "Hi, %{name}" % {name: 'Fred'} => "Hi, Fred"
main > ? String#% From: string.c (C Method): Owner: String Visibility: public Signature: %(arg1) Number of lines: 9 Format---Uses str as a format specification, and returns the result of applying it to arg. If the format specification contains more than one substitution, then arg must be an Array or Hash containing the values to be substituted. See Kernel::sprintf for details of the format string. "%05d" % 123 #=> "00123" "%-5s: %016x" % [ "ID", self.object_id ] #=> "ID : 00002b054ec93168" "foo = %{foo}" % { :foo => 'bar' } #=> "foo = bar"
I guess that built-in version is fine for simple cases. You only need to use
I18n.translate
if you need its more advanced features likeI18n.config.missing_interpolation_argument_handler
.
-
-
github.com github.com
-
github.com github.com
-
call run[] ( or run.call/run.()
-
-
github.com github.com
-
github.com github.com
Tags
Annotators
URL
-
- May 2020
-
github.com github.com
-
-
However, distributing such Ruby apps to inexperienced end users or non-Ruby-programmer end users is problematic. If users have to install Ruby first, or if they have to use RubyGems, they can easily run into problems. Even if they already have Ruby installed, they can still run into problems, e.g. by having the wrong Ruby version installed. The point is, it's a very real problem that could harm your reputation.
-
-
stackoverflow.com stackoverflow.com
-
github.com github.com
-
-
old_log_entries = old_log.split /(?=commit [0-9a-f]{40})/ # Lookahead assertions FTW
-
-
github.com github.com
-
old_log.split /(?=commit [0-9a-f]{40})/ # Lookahead assertions FTW
-
-
github.com github.com
-
muldoon.cloud muldoon.cloud
-
Programming languages These will probably expose my ignorance pretty nicely.
When to use different programming languages (advice from an Amazon employee):
- Java - enterprise applications
- C# - Microsoft's spin on Java (useful in the Microsoft's ecosystem)
- Ruby - when speed is more important then legibility or debugging
- Python - same as Ruby but also for ML/AI (don't forget to use type hinting to make life a little saner)
- Go/Rust - fresh web service where latency and performance were more important than community/library support
- Haskell/Erlang - for very elegant/mathematical functional approach without a lot of business logic
- Clojure - in situation when you love Lisp (?)
- Kotlin/Scala - languages compiling to JVM bytecode (preferable over Clojure). Kotlin works with Java and has great IntelliJ support
- C - classes of applications (operating systems, language design, low-level programming and hardware)
- C++ - robotics, video games and high frequency trading where the performance gains from no garbage collection make it preferable to Java
- PHP/Hack - testing server changes without rebuilding. PHP is banned at Amazon due to security reasons, but its successor, Hack, runs a lot of Facebook and Slack's backends
-
- Apr 2020
-
github.com github.com
-
guides.rubyonrails.org guides.rubyonrails.org
-
The method name is generated by replacing spaces with underscores. The result does not need to be a valid Ruby identifier though, the name may contain punctuation characters etc. That's because in Ruby technically any string may be a method name. This may require use of define_method and send calls to function properly, but formally there's little restriction on the name.
Tags
Annotators
URL
-
-
tenderlovemaking.com tenderlovemaking.com
-
But where is the helper method defined? What’s its visibility? Can I put it in a module? Can I use inheritance? Who can call it? Can I call super from the extracted method? If so, where does super go?
-
-
github.com github.com
-
github.com github.com
-
github.com github.com
Tags
Annotators
URL
-
-
github.com github.com
-
docs.seattlerb.org docs.seattlerb.org
-
minitest doesn't reinvent anything that ruby already provides, like: classes, modules, inheritance, methods. This means you only have to learn ruby to use minitest and all of your regular OO practices like extract-method refactorings still apply.
-
-
github.com github.com
-
Similar to: form_for, but not actually for forms, apparently
Tags
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
-
Ruby 2.1 added local_variable_set, but that cannot create new local variables either
-
-
stackoverflow.com stackoverflow.com
-
binding.local_variable_get and binding.local_variable_set
-
-
stackoverflow.com stackoverflow.com
-
This situation usually arises from external constraints not design choices such as my example with Sequel. My point is that assigning a value to a constant is allowed by Ruby in certain scopes and not others. It used to be up to the developer to choose wisely when to perform the assignment. Ruby changed on this. Not for everyone's good.
-
-
github.com github.com
-
stackoverflow.com stackoverflow.com
-
-
it pollutes the MultiDelegator class with every new delegate. If you use MultiDelegator several times, it will keep adding methods to the class, which is undesirable
-
I came up with a Delegator-like implementation of this that I called DelegatorToAll
-
-
guides.rubyonrails.org guides.rubyonrails.org
-
The handler can be a method or a Proc object passed to the :with option. You can also use a block directly instead of an explicit Proc object.
Example of: letting you either pass a proc (as a keyword arg in this case) or as a block.
-
- Mar 2020
-
rubyworks.github.io rubyworks.github.io
-
Ruby's current handling of Dates and Times is all over the map. We have Date, Time, DateTime, ParseDate, and more, not to mention all the other common extensions running around out there. Ruby needs an improved class that incorporates them all.
-
-
-
github.com github.com
-
Methods must be tested both via a Lemon unit test and as a QED demo. The Lemon unit tests are for testing a method in detail whereas the QED demos are for demonstrating usage.
-
-
stackoverflow.com stackoverflow.com
-
prepend_message
-
To be just a bit polemic, your first instinct was not to do that. And you probably wouldn't think of that in your unit tests either (the holy grail of dynamic langs). So someday it would blow up at runtime, and THEN you'd add that safeguard.
-
As many would guess: ... catch StandardError => e raise $! ... raises the same error referenced by $!, the same as simply calling: ... catch StandardError => e raise ... but probably not for the reasons one might think. In this case, the call to raise is NOT just raising the object in $!...it raises the result of $!.exception(nil), which in this case happens to be $!.
-
-
github.com github.com
Tags
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
stackoverflow.com stackoverflow.com
-
The pattern below has become exceptionally useful for me (pun intended). It's clean, can be easily modularized, and the errors are expressive. Within my class I define new errors that inherit from StandardError, and I raise them with messages (for example, the object associated with the error).
-
-
github.com github.com
-
github.com github.com
Tags
Annotators
URL
-
-
github.com github.com
-
This looks good but https://github.com/jonahb/akismet looks better maintained
-
-
github.com github.com
-
github.com github.com
-
github.com github.com
Tags
Annotators
URL
-
-
bernardic.ca bernardic.ca
-
The popular question in my company these days is “Rails or WordPress?”, but I will probably touch upon the broader questions of “MVC or CMS?” and “Ruby or PHP?”, so you can often substitute “Rails” for “MVC framework” in the article.
-
- Feb 2020
-
github.com github.com
-
github.com github.com
Tags
Annotators
URL
-
-
github.com github.com
Tags
Annotators
URL
-
-
-
github.com github.com
-
-
If you like the straight forward and effective nature of Strong Parameters
-
-
github.com github.com
Tags
Annotators
URL
-
-
rubylearning.com rubylearning.com
-
-
blog.saeloun.com blog.saeloun.com
-
The rules for finding the arity of the methods are as follows:
-
-
The **nil argument was added in Ruby 2.7 to explicity mark that the method accepts no keyword arguments.
-
-
ruby-doc.org ruby-doc.org
-
Returns an indication of the number of arguments accepted by a method. Returns a nonnegative integer for methods that take a fixed number of arguments. For Ruby methods that take a variable number of arguments, returns -n-1, where n is the number of required arguments. Keyword arguments will be considered as a single additional argument, that argument being mandatory if any keyword argument is mandatory. For methods written in C, returns -1 if the call takes a variable number of arguments.
What they fail to mention is that apparently the arity is always -1 if the method is available dynamically (due to
respond_to_missing?
).
Tags
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
-
It's a good practice to create respond_to_missing? if you are overriding method_missing. That way, the class will tell you the method you are calling exists, even though it's not explicitly declared.
-
-
Without respond_to_missing? defined, trying to get the method via method will fail:
-
- Jan 2020
-
github.com github.com
-
-
github.com github.comrvm/rvm1
-
github.com github.com
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
I've often wished for some standard variable to use for blocks and such. Like some people here, I had considered
it
. Usually I use_
but I know that means "unused" to many/most programmers. I like the%
option that Clojure has.
-
-
www.rubyguides.com www.rubyguides.com
- Dec 2019
-
github.com github.com
Tags
Annotators
URL
-
-
github.com github.com
-
github.com github.com
Tags
Annotators
URL
-
- Nov 2019
-
github.com github.com
-
Example of someone else defining a file that simply requires another file because this is the one that
gem
(?) orbundler
(?) looks for when your gem is namedactiverecord-pg_enum
-
-
graphql-ruby.org graphql-ruby.org
Tags
Annotators
URL
-
-
rubykaigi.org rubykaigi.org
- Oct 2019
-
www.typescriptlang.org www.typescriptlang.org
-
In TypeScript, we can also set a value that a parameter will be assigned if the user does not provide one, or if the user passes undefined in its place.
-
buildName(undefined, "Adams")
-
If a default-initialized parameter comes before a required parameter, users need to explicitly pass undefined to get the default initialized value.
-
-
www.hanselman.com www.hanselman.com
-
CoffeeScript is to Ruby as TypeScript is to Java/C#/C++.
-
If you love Ruby, you'll enjoy CoffeeScript as it makes the JavaScript more like the Ruby.
-
- Sep 2019
-
github.com github.com
Tags
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
-
Open3.capture2e
-
- Aug 2019
-
www.reddit.com www.reddit.com
-
Websites where to find out challenges
-
-
www.toptal.com www.toptal.com
-
Best programming practices for Ruby
-
- Feb 2019
- Jan 2016
-
daniel-azuma.com daniel-azuma.com
-
require 'active_record/connection_adapters/postgis_adapter/railtie'
The following worked better in my setup:
require 'active_record/connection_adapters/postgis/railtie'
Tags
Annotators
URL
-
-
www.ruby-lang.org www.ruby-lang.org
-
with another instance as its receiver
An instance can call private methods of another instance of the same class.
-
- Nov 2015
-
www.aozora.gr.jp www.aozora.gr.jp
-
まぶた)
Testing a highlight on Ruby text.
Highlight is meant to wrap this image:
Highlight is also meant to include the super-script hiragana characters: まぶた
Actual highlight includes the hiragana characters "まぶた" as well as ")"
-
- Jul 2015
-
www.venturesity.com www.venturesity.com
-
Up for a Challenge?
Do you have what it takes? Signup on www.venturesity.com and unlock opportunities.
-
- May 2015
-
www.eriktrautman.com www.eriktrautman.com
-
Just to focus on the differences between lambdas and Procs, a lambda acts more like a real method. What does that mean?
Apparently it means a lambda is less ($@(#$ insane.
-
When you create your own function to accept procs, the guts need to change a little bit because you'll need to use #call instead of yield inside (because which proc would yield run if you had more than one?).
Too much special!! Why the special cases? Just so that one can type
yield
instead of invoking a function and naming the argument? -
Use that block of code (now called a Proc) as an input to a function by prepending it with an apersand &
Oh, Ruby. This is entirely too confusing. Why is the ampersand required to signify that something is passed as a block, especially given that it has a type (
Proc
)? What does it mean if the ampersand isn't used?
-