7

How to Make a Ruby Sub-Chain

 2 years ago
source link: https://www.codesd.com/item/how-to-make-a-ruby-sub-chain.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Make a Ruby Sub-Chain

advertisements

This question already has an answer here:

  • Extract a substring from a string in Ruby using a regular expression 5 answers

I'm very new to ruby, in fact I just read it today. But I need to do something quick in Ruby, suppose I have a string ABC=180000. What I want to do is remove the last two chars and makes it become 8 chars of string, so the above case result should be 00001800

in case the string ABC=AA000, the final result is 00000AA0

Could you guys tell me how to do this quickly?

Thanks a lot!


Untested as send from mobile:

"180000"[0...-2].rjust 8,"0"

Have a look at the docs: http://ruby-doc.org/core-2.2.3/String.html

Related Articles

How to make this ruby ​​code more readable?

Take the sample ruby code, how to rewrite/indent it so the following ruby code to make it more readable & make sure it fits in one line i.e 80-90chars? %w(survey survey_section question_group question dependency dependency_condition answer answer_typ

How to make a javascript promise chaining more elegantly?

I work on my Angular2/firebase side project and stop for a while on this chunk of code. What I am trying to do here is to create a new account with signupUser method and then, only when it succeeded, call another method saveNewUserInDatabase. If I do

How to make a Ruby class as a chopped with Setter

For academic reasons, I'd like to make an instance of Ruby class act like a hash. GOALS Initialize MyClass instance with a hash # success Request values from instance of myClass, like a hash # success Then set properties as a hash # fail Although som

I'm a little lost: how to make rails / ruby ​​on a website?

Ok, long time php guy doing my best to pick up ruby on rails by developing a small website for myself using only ror instead of php. However i'm a bit stuck, and i think it is because i'm not exactly understanding how rails actually works. I am runni

Java: How to make a final sub-array?

Consider the following snippet: public class TestBench { private static final short matrix[][] = new short[][] {new short[] {}}; public static void main (String args[]) { matrix = new short[][] {new short[] {}}; // illegal matrix[0] = new short[] {};

How to make a function / sub-section available for all forms of a project?

I have a sub that I want to be available to (or "callable from") all forms: ' Call some Sub from another form. someSub() I'm having difficulty finding examples online thus my suspicion that the crux of my issue may be terminological. How? Can an

How to make a ruby ​​command line application with a pager?

I'm making a command line tool using Ruby. It will print a lot of text on screen. Currently, I'm using shell pipeline (may_app | more) to do so. But I think it's better to has a default pager. It's just like what you see when execute git log . One ca

How to make PHP faster: does chain creation cost?

In this question a code bit is presented and the questioner wants to make it faster by eliminating the use of variables. Seems to me he's looking in the wrong place, but far be it from me to know. Here's the code while ($item = current($data)) { echo

Unable to understand how to make the ruby ​​'encryptor' base work

Basically want to make 'abc' into 'bcd'. I was thinking if I add the letter the follows the first to the end of the phrase and dropped the original first letter, eventually I'd get the final solution. Got kinda stuck and was hoping someone could shed

Part II: How to make Ruby AES-256-CBC and PHP MCRYPT_RIJNDAEL_128 play well together

This question is a continuation of my last one, regarding How to make Ruby AES-256-CBC and PHP MCRYPT_RIJNDAEL_128 play well together. I've got that working now, but I'm still struggling to go the other direction. The PHP generated cryptogram appears

How to make Maven find sibling modules, when mvn is running in the submodule directory?

For example, I have a game project: superegg/ |- game/ | `- pom.xml -> (a lot of jars.) |- ai/ | `- pom.xml |- sprite/ | |- egg/ | | `- pom.xml -> sprite | |- badguy/ | | `- pom.xml -> sprite, ai | `- pom.xml -> game ` pom.xml (Here --> mea

How to make rails work with vue.js?

Well my question is simple, how to make a Ruby on Rails app work with Vue.js? The details I first look at the vue-rails gem, but that add Vue to the rails asset pipeline, and I want to work with other npm packages, like browserify. Then I look to tha

how to make a sub-submenu with css?

http://i.imgur.com/DbMCI.jpg http://i.imgur.com/i9r6N.jpg Please see image above, what I want to do is push "gloves" and "boots" tab to the left of "blah UGG" I tried to set the sub menu to position relative and the sub sub m

How to make Ruby structures?

I'd like to know how to make structs using a class. I know this sounds a bit abstract, but this is what I'd like to achieve: class Person < StructHelper string :name string :last_name int :age long :birth_date def handle() puts "My name is #{name}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK