Sign Up Now!

Sign up and get personalized intelligence briefing delivered daily.


Sign Up

Articles related to "ruby"


Repl.it GFX: Native graphics development in the browser

  • And today, we're excited to bring native GUI applications and game development to the browser.
  • We want programmers from all backgrounds, regardless of their language, to be able to code games and apps with ease.
  • Plus, supporting native graphics opens us up to a wealth of frameworks, games, and educational material!
  • Right now, we're piping the X Window system through VNC through WebSockets to your browser, which is not the most efficient way to do this — we have a lot of ideas on how we could improve it.
  • Finally, depending on how far you are from our data center (US-central) you might feel a delay, which we're also working on making better by replicating our data center (watch out Google Stadia).
  • We're supporting these frameworks out of the box, but very soon, we'll roll this out to all of our languages.

save | comments | report | share on


Function/Method look up in Elixir/Ruby

  • I love to compare what I'm learning in Elixir back to what I know in Ruby, as I think that really strengthens my understanding of both languages.
  • Before we jump into Elixir, let's first look at how method lookup in Ruby works.
  • With that, we know that if we want to inject a function into Ruby, we just have to make sure that the newly injected function is the first method that gets found during the lookup (defining #ancestors anywhere before BasicObject).
  • In his post, José clarified defoverridable for me, but he also went on to say that defoverridable is not recommended, and they are in fact moving towards to @optional_callback to mark methods as optional, along with an enhancement @impl (which the compiler will use to make sure "child" implements that function), so that was also an interesting thing that I learned.

save | comments | report | share on


Using `Hash#fetch` in Ruby for better nil handling

  • Let’s look at an example of a classifieds site that sorts its listings when displaying them for the user, and some of the ways we can use Hash#fetch to proactively handle those nils before they happen.
  • There’s many ways to handle this problem, for example, we could set a default with the || operator.
  • With Hash#fetch, if a key is not found in a hash, we can provide a default key to look for, which is quite a nice way to handle our nil situation.
  • Semantics alone aren’t a great reason to use this pattern though, so lets look at some more interesting examples where Hash#fetch can be used to proactively handle nils.
  • In the case where you don’t find what you’re looking for in a hash, returning a default value is nice, as we’ve seen.

save | comments | report | share on


Using `Hash#fetch` in Ruby for better nil handling

  • Let’s look at an example of a classifieds site that sorts its listings when displaying them for the user, and some of the ways we can use Hash#fetch to proactively handle those nils before they happen.
  • There’s many ways to handle this problem, for example, we could set a default with the || operator.
  • With Hash#fetch, if a key is not found in a hash, we can provide a default key to look for, which is quite a nice way to handle our nil situation.
  • Semantics alone aren’t a great reason to use this pattern though, so lets look at some more interesting examples where Hash#fetch can be used to proactively handle nils.
  • In the case where you don’t find what you’re looking for in a hash, returning a default value is nice, as we’ve seen.

save | comments | report | share on


Integrate Stripe in your Ruby on Rails app

  • We need to run 'rails s' in terminal and go to the following page: localhost:3000/users/sign_up.
  • We are changing a bit our app/views/billing/index.html.erb in order to call an action create_card when we submit our form.
  • And if we go on Stripe in Customers (don't forget to switch to test data) we should see an email and card info of our user.
  • We need to go to our Stripe dashboard => Billing => Products and click on the button "New".
  • Create your product with 2 pricing plan.
  • Now we need to subscribe our user to the plan that he will choose.
  • So we need to create a new action which will link our customer to the plan and create a subscription.
  • To check everything worked, go to Stripe, Dashboard => Billing => Subscriptions.

save | comments | report | share on


Cables vs. malloc_trim, or yet another Ruby memory usage benchmark

  • The author has proposed a very simple patch to Ruby's (MRI, to be precise) garbage collector: to add a call to malloc_trim at the very end of the full GC cycle and release some allocated memory back to the kernel.
  • So, I decided to measure the impact of the patch on Action Cable that is somewhat infamous for its speed and memory usage (check out AnyCable for a speedier replacement).
  • I usually do Action Cable benchmarks when some new things appear: either new web servers (e.g., see the benchmarks for Iodine and Falcon) or novel Ruby features (like the malloc_trim patch or the upcoming GC.compact) that I plan to try out next time.
  • That means that both memory usage and performance is better with the less number of malloc arenas.

save | comments | report | share on